package com.waveset.adapter;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import com.sun.idm.logging.trace.Trace;
import com.sun.idm.logging.trace.TraceManager;
import com.waveset.adapter.iapi.IAPI;
import com.waveset.adapter.iapi.IAPIException;
import com.waveset.adapter.iapi.IAPIFactory;
import com.waveset.adapter.iapi.IAPIProcess;
import com.waveset.adapter.util.OracleLobUtil;
import com.waveset.msgcat.ErrorMessage;
import com.waveset.msgcat.Message;
import com.waveset.msgcat.Severity;
import com.waveset.object.AccountAttributeType;
import com.waveset.object.Attribute;
import com.waveset.object.Constants;
import com.waveset.object.GenericObject;
import com.waveset.object.Resource;
import com.waveset.object.ResourceInfo;
import com.waveset.object.Syntax;
import com.waveset.object.WSAttribute;
import com.waveset.object.WSUser;
import com.waveset.object.WavesetResult;
import com.waveset.ui.web.resources.wizard.DBTableUtil;
import com.waveset.util.Binary;
import com.waveset.util.EncryptedData;
import com.waveset.util.InternalError;
import com.waveset.util.PooledConnection;
import com.waveset.util.Util;
import com.waveset.util.VariableExpander;
import com.waveset.util.VariableResolver;
import com.waveset.util.WavesetException;

public class InformixDBResourceAdapter extends JdbcResourceAdapter
implements ActiveSync
{
	public static final String code_id = "$Id: InformixDBResourceAdapter.java,v 1.52 2009/01/13 04:50:28 sb154400 Exp $";
	private static final String CLASS = "com.waveset.adapter.InformixDBResourceAdapter";
	private static final Trace TRACE = TraceManager.getTrace("com.waveset.adapter.InformixDBResourceAdapter");
	public static final String RA_TABLE = "Table";
	public static final String RA_KEY_COLUMN = "Key Column";
	public static final String RA_PASSWORD_COLUMN = "Password Column";
	public static final String RA_NO_PASSWORDS = "noPasswords";
	public static final String RA_ENABLE_EMPTY_STRING = "enableEmptyString";
	public static final String RA_NATIVE_TIMESTAMPS = "nativeTimestamps";
	public static final String DEFAULT_PORT = "9089";
	public static final String DEFAULT_DRIVER = "com.informix.jdbc.IfxDriver";
	//public static final String DEFAULT_TEMPLATE = "jdbc:informix-sqli://%h:%p/%d";
	public static final String DEFAULT_TEMPLATE = "jdbc:informix-sqli://localhost:9089/proteus:INFORMIXSERVER=ol_ids_1150_1";
	ActiveSyncUtil _util;
	public static final String RA_STATIC_SEARCH_PREDICATE = "Static Search Predicate";

	/** @deprecated */
	public static final String RA_PROCESS_NAME = "Process to run with changes";
	public static final String LAST_FETCHED_PREDICATE = "Last Fetched Predicate";
	public static final String LAST_FETCHED_CONJUNCTION = "Last Fetched Conjunction";
	public static final String ORDER_BY_CLAUSE = "Order By Clause";
	private static final String PROP_PROCESSED = "lastProcessed";
	/* */  // static final String prototypeXml = "<Resource name='Informix DB Adapter'           class='com.waveset.adapter.InformixDBTableResourceAdapter'           typeString='Database Table'            facets='provision' value ='Informix' >\n  <ResourceAttributes>\n    <ResourceAttribute name='Quoting' displayName='RAMessages:RESATTR_DBTABLE_QUOTING'\n      description='RAMessages:RESATTR_HELP_DBTABLE_QUOTING'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Host' displayName='RESATTR_HOST'\n      description='RESATTR_HELP_DBTABLE_HOST'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Port' displayName='RESATTR_PORT' value='1521'\n      description='RESATTR_HELP_DBTABLE_PORT'>\n    </ResourceAttribute>\n    <ResourceAttribute name='User' displayName='RESATTR_USER'\n      description='RESATTR_HELP_DBTABLE_USER'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Password' displayName='RESATTR_PASSWORD' type='encrypted'\n      description='RESATTR_HELP_DBTABLE_PASSWORD'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Database' displayName='RESATTR_DATABASE'\n       description='RESATTR_HELP_DBTABLE_DATABASE'\n>    </ResourceAttribute>\n    <ResourceAttribute name='Table' displayName='RESATTR_TABLE'\n       description='RESATTR_HELP_DBTABLE_TABLE'\n>    </ResourceAttribute>\n    <ResourceAttribute name='Key Column' displayName='RESATTR_KEY_COLUMN'\n       description='RESATTR_HELP_DBTABLE_KEY_COLUMN'\n>    </ResourceAttribute>\n    <ResourceAttribute name='Password Column' displayName='RESATTR_PASSWORD_COLUMN'\n       description='RESATTR_HELP_DBTABLE_PASSWORD_COLUMN'\n>    </ResourceAttribute>\n    <ResourceAttribute name='JDBC Driver' displayName='RESATTR_JDBC_DRIVER'\n      description='RESATTR_HELP_DBTABLE_DRIVER'    " +"  value='com.informix.jdbc.IfxDriver'>\n    </ResourceAttribute>\n    <ResourceAttribute name='JDBC URL Template' displayName='RESATTR_URL_TEMPLATE'\n      description='RESATTR_HELP_DBTABLE_URL_TEMPLATE'\n   " +"   value='jdbc:informix-sqli://%h:%p/%d'>\n    </ResourceAttribute>\n    <ResourceAttribute name='idleTimeout' displayName='com.waveset.adapter.RAMessages:RESATTR_DBPOOL_IDLETIMEOUT' type='string' multi='false'\n       description='com.waveset.adapter.RAMessages:RESATTR_DBPOOL_IDLETIMEOUT_HELP'\n       value='600'>\n    </ResourceAttribute>\n    <ResourceAttribute name='enableEmptyString' displayName='com.waveset.adapter.RAMessages:RESATTR_DBTABLE_ENABLE_EMPTY_STRING' type='boolean'\n      description='com.waveset.adapter.RAMessages:RESATTR_DBTABLE_ENABLE_EMPTY_STRING_HELP'\n      value='false'>\n    </ResourceAttribute>\n     <ResourceAttribute name='noPasswords' displayName='com.waveset.adapter.RAMessages:RESATTR_NOPASSWORDS' type='" + Syntax.BOOLEAN.getName() + "'\n" + "        description='" + "com.waveset.adapter.RAMessages:DBTABLE_NOPASSWORDS_HELP" + "'/>\n" + "     <ResourceAttribute name='" + "rethrowAllSQLExceptions" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_RETHROW_ALL_SQLEXCEPTIONS" + "' type='" + Syntax.BOOLEAN.getName() + "'\n" + "        description='" + "com.waveset.adapter.RAMessages:RESATTR_HELP_RETHROW_ALL_SQLEXCEPTIONS" + "'/>\n" + "     <ResourceAttribute name='" + "nativeTimestamps" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_NATIVE_TIMESTAMPS" + "' type='" + Syntax.BOOLEAN.getName() + "'\n" + "        description='" + "com.waveset.adapter.RAMessages:DBTABLE_NATIVE_TIMESTAMPS_HELP" + "'/>\n" + "    <ResourceAttribute name='" + "Static Search Predicate" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_STATIC_SEARCH_PREDICATE" + "' type='string' multi='false'\n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_HELP_STATIC_SEARCH_PREDICATE" + "' facets='activesync' >\n" + "   </ResourceAttribute>\n" + "    <ResourceAttribute name='" + "Last Fetched Conjunction" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_LAST_FETCHED_CONJUNCTION" + "' type='string' multi='false' value='AND' \n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_LAST_FETCHED_CONJUNCTION_HELP" + "' facets='activesync' >\n" + "    </ResourceAttribute>\n" + "    <ResourceAttribute name='" + "Last Fetched Predicate" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_LAST_FETCHED_PREDICATE" + "' type='string' multi='false'\n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_LAST_FETCHED_PREDICATE_HELP" + "' facets='activesync' >\n" + "    </ResourceAttribute>\n" + "    <ResourceAttribute name='" + "Order By Clause" + "' displayName='" + "com.waveset.adapter.RAMessages:DBTABLE_ORDER_BY" + "' type='string' multi='false'\n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_ORDER_BY_HELP" + "' facets='activesync' >\n" + "    </ResourceAttribute>\n" + "    <ResourceAttribute name='ignoreEventFailures' displayName='com.waveset.adapter.RAMessages:RESATTR_IGN_ACT_SYNC_FAILURES' type='boolean' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_IGN_ACT_SYNC_FAILURES_HELP' facets='activesync' >\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='processRule' displayName='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='correlationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE_HELP' facets='activesync' value='CORRELATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='confirmationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE_HELP' facets='activesync' value='CONFIRMATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='deleteRule' displayName='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='createUnmatched' displayName='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED' type='string' multi='false' value='true'\n      description='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='resolveProcessRule' displayName='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='populateGlobal' displayName='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL' type='string' multi='false' value='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL_HELP' facets='activesync'>\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='Proxy Administrator' displayName='com.waveset.adapter.RAMessages:RESATTR_PROXY_ADMINISTRATOR' type='string' multi='false' value='Configurator'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_30'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Input Form' displayName='com.waveset.adapter.RAMessages:RESATTR_FORM' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_26'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Pre-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW_HELP'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Post-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW_HELP'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Archives' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_ARCHIVES' type='string' multi='false'  value='3'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_ARCHIVES'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Age Length' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Age Unit' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE_UNIT' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE_UNIT'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Log Level' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_LEVEL' type='string' multi='false' value='2'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_27'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Log File Path' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_PATH' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_28'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Log File Size' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_SIZE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_29'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Scheduling Interval' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_51'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Poll Every' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL_COUNT' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_52'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Time' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_TIME' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_56'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Date' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_DATE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_54'>\n    </ResourceAttribute>\n    <ResourceAttribute name='assignSourceOnCreate' displayName='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE' type='boolean' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE_HELP' facets='activesync' value='true'>\n    </ResourceAttribute>\n" + "  </ResourceAttributes>\n" + "  <Template>\n" + "    <AttrDef name='accountId' type='string' />\n" + "  </Template>\n" + "<AccountAttributeTypes>\n" + "</AccountAttributeTypes>\n" + "  <LoginConfigEntry name='" + "com.waveset.security.authn.WSResourceLoginModule" + "' type='" + "Database Table" + "' displayName='" + "com.waveset.adapter.RAMessages:RES_LOGIN_MOD_DBTABLE" + "'>\n" + "    <AuthnProperties>\n" + "      <AuthnProperty name='" + "db_user" + "' displayName='" + "com.waveset.adapter.RAMessages:UI_USERID_LABEL" + "' formFieldType='text' isId='true' />\n" + "      <AuthnProperty name='" + "db_password" + "' displayName='" + "com.waveset.adapter.RAMessages:UI_PWD_LABEL" + "' formFieldType='password'/>\n" + "    </AuthnProperties>\n" + "    <SupportedApplications>\n" + "      <SupportedApplication name='" + "Administrator Interface" + "'/>\n" + "      <SupportedApplication name='" + "User Interface" + "'/>\n" + "    </SupportedApplications>\n" + "  </LoginConfigEntry>\n" + "  <ResourceUserForm>\n" + "    <ObjectRef id='" + "#ID#" + "Database Table User Form' type='" + "UserForm" + "'/>\n" + "  </ResourceUserForm>\n" + "</Resource>\n";
	/**
	 * The name of an existing user account that new users will be modeled after.
	 */
	public static final String RA_USERMODEL = "Usermodel";


	//static final String prototypeXml = "<Resource name='Informix Database Table'           class='com.waveset.adapter.InformixDBResourceAdapter'           typeString='Informix Database Table'           syncSource='true'  facets='provision' >\n  <ResourceAttributes>\n    <ResourceAttribute name='Quoting' displayName='RAMessages:RESATTR_DBTABLE_QUOTING'\n      description='RAMessages:RESATTR_HELP_DBTABLE_QUOTING'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Host' displayName='RESATTR_HOST'\n      description='RESATTR_HELP_DBTABLE_HOST'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Port' displayName='RESATTR_PORT' value='1521'\n      description='RESATTR_HELP_DBTABLE_PORT'>\n    </ResourceAttribute>\n    <ResourceAttribute name='User' displayName='RESATTR_USER'\n      description='RESATTR_HELP_DBTABLE_USER'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Password' displayName='RESATTR_PASSWORD' type='encrypted'\n      description='RESATTR_HELP_DBTABLE_PASSWORD'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Database' displayName='RESATTR_DATABASE'\n       description='RESATTR_HELP_DBTABLE_DATABASE'\n>    </ResourceAttribute>\n    <ResourceAttribute name='Table' displayName='RESATTR_TABLE'\n       description='RESATTR_HELP_DBTABLE_TABLE'\n>    </ResourceAttribute>\n    <ResourceAttribute name='Key Column' displayName='RESATTR_KEY_COLUMN'\n       description='RESATTR_HELP_DBTABLE_KEY_COLUMN'\n>    </ResourceAttribute>\n    <ResourceAttribute name='Password Column' displayName='RESATTR_PASSWORD_COLUMN'\n       description='RESATTR_HELP_DBTABLE_PASSWORD_COLUMN'\n>    </ResourceAttribute>\n    <ResourceAttribute name='JDBC Driver' displayName='RESATTR_JDBC_DRIVER'\n      description='RESATTR_HELP_DBTABLE_DRIVER'      value='oracle.jdbc.driver.OracleDriver'>\n    </ResourceAttribute>\n    <ResourceAttribute name='JDBC URL Template' displayName='RESATTR_URL_TEMPLATE'\n      description='RESATTR_HELP_DBTABLE_URL_TEMPLATE'\n      value='jdbc:oracle:thin:@%h:%p:%d'>\n    </ResourceAttribute>\n    <ResourceAttribute name='idleTimeout' displayName='com.waveset.adapter.RAMessages:RESATTR_DBPOOL_IDLETIMEOUT' type='string' multi='false'\n       description='com.waveset.adapter.RAMessages:RESATTR_DBPOOL_IDLETIMEOUT_HELP'\n       value='600'>\n    </ResourceAttribute>\n    <ResourceAttribute name='enableEmptyString' displayName='com.waveset.adapter.RAMessages:RESATTR_DBTABLE_ENABLE_EMPTY_STRING' type='boolean'\n      description='com.waveset.adapter.RAMessages:RESATTR_DBTABLE_ENABLE_EMPTY_STRING_HELP'\n      value='false'>\n    </ResourceAttribute>\n     <ResourceAttribute name='noPasswords' displayName='com.waveset.adapter.RAMessages:RESATTR_NOPASSWORDS' type='" + Syntax.BOOLEAN.getName() + "'\n" + "        description='" + "com.waveset.adapter.RAMessages:DBTABLE_NOPASSWORDS_HELP" + "'/>\n" + "     <ResourceAttribute name='" + "rethrowAllSQLExceptions" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_RETHROW_ALL_SQLEXCEPTIONS" + "' type='" + Syntax.BOOLEAN.getName() + "'\n" + "        description='" + "com.waveset.adapter.RAMessages:RESATTR_HELP_RETHROW_ALL_SQLEXCEPTIONS" + "'/>\n" + "     <ResourceAttribute name='" + "nativeTimestamps" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_NATIVE_TIMESTAMPS" + "' type='" + Syntax.BOOLEAN.getName() + "'\n" + "        description='" + "com.waveset.adapter.RAMessages:DBTABLE_NATIVE_TIMESTAMPS_HELP" + "'/>\n" + "    <ResourceAttribute name='" + "Static Search Predicate" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_STATIC_SEARCH_PREDICATE" + "' type='string' multi='false'\n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_HELP_STATIC_SEARCH_PREDICATE" + "' facets='activesync' >\n" + "   </ResourceAttribute>\n" + "    <ResourceAttribute name='" + "Last Fetched Conjunction" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_LAST_FETCHED_CONJUNCTION" + "' type='string' multi='false' value='AND' \n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_LAST_FETCHED_CONJUNCTION_HELP" + "' facets='activesync' >\n" + "    </ResourceAttribute>\n" + "    <ResourceAttribute name='" + "Last Fetched Predicate" + "' displayName='" + "com.waveset.adapter.RAMessages:RESATTR_LAST_FETCHED_PREDICATE" + "' type='string' multi='false'\n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_LAST_FETCHED_PREDICATE_HELP" + "' facets='activesync' >\n" + "    </ResourceAttribute>\n" + "    <ResourceAttribute name='" + "Order By Clause" + "' displayName='" + "com.waveset.adapter.RAMessages:DBTABLE_ORDER_BY" + "' type='string' multi='false'\n" + "      description='" + "com.waveset.adapter.RAMessages:DBTABLE_ORDER_BY_HELP" + "' facets='activesync' >\n" + "    </ResourceAttribute>\n" + "    <ResourceAttribute name='ignoreEventFailures' displayName='com.waveset.adapter.RAMessages:RESATTR_IGN_ACT_SYNC_FAILURES' type='boolean' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_IGN_ACT_SYNC_FAILURES_HELP' facets='activesync' >\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='processRule' displayName='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='correlationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE_HELP' facets='activesync' value='CORRELATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='confirmationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE_HELP' facets='activesync' value='CONFIRMATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='deleteRule' displayName='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='createUnmatched' displayName='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED' type='string' multi='false' value='true'\n      description='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='resolveProcessRule' displayName='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='populateGlobal' displayName='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL' type='string' multi='false' value='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL_HELP' facets='activesync'>\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='Proxy Administrator' displayName='com.waveset.adapter.RAMessages:RESATTR_PROXY_ADMINISTRATOR' type='string' multi='false' value='Configurator'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_30'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Input Form' displayName='com.waveset.adapter.RAMessages:RESATTR_FORM' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_26'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Pre-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW_HELP'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Post-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW_HELP'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Archives' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_ARCHIVES' type='string' multi='false'  value='3'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_ARCHIVES'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Age Length' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Age Unit' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE_UNIT' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE_UNIT'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Log Level' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_LEVEL' type='string' multi='false' value='2'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_27'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Log File Path' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_PATH' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_28'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Maximum Log File Size' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_SIZE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_29'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Scheduling Interval' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_51'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Poll Every' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL_COUNT' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_52'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Time' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_TIME' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_56'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Date' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_DATE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_54'>\n    </ResourceAttribute>\n    <ResourceAttribute name='assignSourceOnCreate' displayName='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE' type='boolean' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE_HELP' facets='activesync' value='true'>\n    </ResourceAttribute>\n" + "  </ResourceAttributes>\n" 

	static final String prototypeXml =
		"<Resource name='INFORMIXActiveSyncAdpator new' class='com.waveset.adapter.InformixDBResourceAdapter' typeString='INFORMIX ActiveSync new' syncSource='true'  facets='activesync' typeDisplayString='"+RAMessages.RESTYPE_INFORMIXSQL+"'>\n"+
		"  <ResourceAttributes>\n"+
		"  <ResourceAttribute name='"+RA_HOST+"' displayName='"+RAMessages.RESATTR_HOST+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_HOST+"'>\n"+
		"    </ResourceAttribute>\n"+
		"    <ResourceAttribute name='"+RA_PORT+"' displayName='"+RAMessages.RESATTR_PORT+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_PORT+"' facets='provision' value='1433'>\n"+
		" 	</ResourceAttribute>\n"+
		"    <ResourceAttribute name='"+RA_USER+"' displayName='"+RAMessages.RESATTR_USER+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_USER+"' facets='provision' value='user name'>\n"+
		"    </ResourceAttribute>\n"+
		"    <ResourceAttribute name='"+RA_PASSWORD+"' displayName='"+RAMessages.RESATTR_PASSWORD+"' type='encrypted' multi='false'\n"+"description='"+RAMessages.RESATTR_PASSWORD+"' facets='provision'>\n"+
		"    </ResourceAttribute>\n"+
		"    <ResourceAttribute name='"+RA_DATABASE+"' displayName='"+RAMessages.RESATTR_DATABASE+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_DATABASE+"' facets='provision'>\n"+
		"    </ResourceAttribute>\n"+
		"    <ResourceAttribute name='Table' displayName='"+RAMessages.RESATTR_TABLE+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_TABLE+"' facets='provision'>\n"+
		"    </ResourceAttribute>\n"+
		"    <ResourceAttribute name='Key Column' displayName='"+RAMessages.RESATTR_KEY_COLUMN+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_KEY_COLUMN+"' facets='provision'>\n"+
		"    </ResourceAttribute>\n"+
		"    <ResourceAttribute name='"+RAMessages.RESATTR_JDBC_DRIVER+"' displayName='"+RAMessages.RESATTR_JDBC_DRIVER+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_JDBC_DRIVER+"' facets='provision' value='com.informix.jdbc.IfxDriver'>\n"+
		"    </ResourceAttribute>\n"+
		"    <ResourceAttribute name='"+RAMessages.RESATTR_URL_TEMPLATE+"' displayName='"+RAMessages.RESATTR_URL_TEMPLATE+"' type='string' multi='false'\n"+"description='"+RAMessages.RESATTR_URL_TEMPLATE+"' facets='provision' value='jdbc:informix-sqli://%h:%p/%d'>\n"+
		"    </ResourceAttribute>\n"+
		"	<ResourceAttribute name='Proxy Administrator' displayName='com.waveset.adapter.RAMessages:RESATTR_PROXY_ADMINISTRATOR' type='string' multi='false' value='Configurator'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_30'>\n" +
		"    </ResourceAttribute>\n    " +
		"   <ResourceAttribute name='Input Form' displayName='com.waveset.adapter.RAMessages:RESATTR_FORM' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_26'>\n " +
		"   </ResourceAttribute>\n " +
		"   <ResourceAttribute name='Pre-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_PREPOLL_WORKFLOW_HELP'>\n   " +
		" </ResourceAttribute>\n " +
		"   <ResourceAttribute name='Post-Poll Workflow' displayName='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POSTPOLL_WORKFLOW_HELP'>\n " +
		"   </ResourceAttribute>\n  " +
		"  <ResourceAttribute name='Maximum Archives' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_ARCHIVES' type='string' multi='false'  value='3'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_ARCHIVES'>\n   " +
		" 	</ResourceAttribute>\n   " +
		" <ResourceAttribute name='Maximum Age Length' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE'>\n    " +
		"	</ResourceAttribute>\n    " +
		"<ResourceAttribute name='Maximum Age Unit' displayName='com.waveset.adapter.RAMessages:RESATTR_MAX_LOG_AGE_UNIT' type='string' multi='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_MAX_LOG_AGE_UNIT'>\n    " +
		"	</ResourceAttribute>\n  " +
		" <ResourceAttribute name='Log Level' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_LEVEL' type='string' multi='false' value='2'\n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_27'>\n    </ResourceAttribute>\n " +
		"  <ResourceAttribute name='Log File Path' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_PATH' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_28'>\n    " +
		"</ResourceAttribute>\n " +
		" <ResourceAttribute name='Maximum Log File Size' displayName='com.waveset.adapter.RAMessages:RESATTR_LOG_SIZE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_29'>\n    </ResourceAttribute>\n " +
		" <ResourceAttribute name='Scheduling Interval' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_51'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Poll Every' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_INTERVAL_COUNT' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_52'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Time' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_TIME' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_56'>\n    </ResourceAttribute>\n    <ResourceAttribute name='Polling Start Date' displayName='com.waveset.adapter.RAMessages:RESATTR_SCHEDULE_START_DATE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_HELP_54'>\n    </ResourceAttribute>\n    <ResourceAttribute name='assignSourceOnCreate' displayName='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE' type='boolean' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_ASSIGN_SOURCE_ON_CREATE_HELP' facets='activesync' value='true'>\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='processRule' displayName='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='correlationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CORRELATION_RULE_HELP' facets='activesync' value='CORRELATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='confirmationRule' displayName='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_CONFIRMATION_RULE_HELP' facets='activesync' value='CONFIRMATION_RULE_NONE'>\n    </ResourceAttribute>\n    <ResourceAttribute name='deleteRule' displayName='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_DELETE_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='createUnmatched' displayName='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED' type='string' multi='false' value='true'\n      description='com.waveset.adapter.RAMessages:RESATTR_CREATE_UNMATCHED_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='resolveProcessRule' displayName='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE' type='string' multi='false' \n      description='com.waveset.adapter.RAMessages:RESATTR_RESOLVE_PROCESS_RULE_HELP' facets='activesync'>\n    </ResourceAttribute>\n    <ResourceAttribute name='populateGlobal' displayName='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL' type='string' multi='false' value='false'\n      description='com.waveset.adapter.RAMessages:RESATTR_POPULATE_GLOBAL_HELP' facets='activesync'>\n    </ResourceAttribute>\n" + "    <ResourceAttribute name='Name3'\n" + "                       displayName='Name3'\n" + "                       type='" + Syntax.STRING.getName() + "'\n" + "                       multi='false'\n" + "                       description='This is used only during active sync'\n" + "                       facets='activesync'/>\n"+ 
		"</ResourceAttributes>\n"+
		"  <Template>\n"+
		"    <AttrDef name='email' type='string' />\n"+
		"  </Template>\n"

		//
		// Specify account attributes and default schema mappings
		//
		+" <AccountAttributeTypes>\n"
		+ "    <AccountAttributeType name='accountId'\n"
		+ "                          mapName='id'\n"
		+ "                          mapType='string'\n"
		+ "                          required='true'>\n"
		+ "      <AttributeDefinitionRef>\n"
		+ "        <ObjectRef type='AttributeDefinition'\n"
		+ "                   name='accountId'/>\n"
		+ "      </AttributeDefinitionRef>\n"
		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='firstname'\n"
		+ "                          mapName='first_name'\n"
		+ "                          mapType='string'\n"
		+ "                          required='true'>\n"
		+ "      <AttributeDefinitionRef>\n"
		+ "        <ObjectRef type='AttributeDefinition'\n"
		+ "                   name='firstname'/>\n"
		+ "      </AttributeDefinitionRef>\n"
		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='lastname'\n"
		+ "                          mapName='last_name'\n"
		+ "                          mapType='string'\n"
		+ "                          required='true'>\n"
		+ "      <AttributeDefinitionRef>\n"
		+ "        <ObjectRef type='AttributeDefinition'\n"
		+ "                   name='lastname'/>\n"
		+ "      </AttributeDefinitionRef>\n"
		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='CategoryId'\n"
		//		+ "                          mapName='category_id'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='true'>\n"
		//		+ "      <AttributeDefinitionRef>\n"
		//		+ "        <ObjectRef type='AttributeDefinition'\n"
		//		+ "                   name='CategoryId'/>\n"
		//		+ "      </AttributeDefinitionRef>\n"
		//		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='initials'\n"
		+ "                          mapName='initials'\n"
		+ "                          mapType='string'\n"
		+ "                          required='false'>\n"
		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='department'\n"
		+ "                          mapName='department'\n"
		+ "                          mapType='int'\n"
		+ "                          required='false'>\n"
		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='employee'\n"
		+ "                          mapName='employee'\n"
		+ "                          mapType='string'\n"
		+ "                          required='false'>\n"
		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='type'\n"
		+ "                          mapName='type'\n"
		+ "                          mapType='int'\n"
		+ "                          required='false'>\n"
		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='SlotNumber'\n"
		+ "                          mapName='slot_number'\n"
		+ "                          mapType='int'\n"
		+ "                          required='false'>\n"
		+ "    </AccountAttributeType>\n"
		+ "    <AccountAttributeType name='facility'\n"
		+ "                          mapName='facility'\n"
		+ "                          mapType='int'\n"
		+ "                          required='false'>\n"
		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='address1'\n"
		//		+ "                          mapName='address1'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='address2'\n"
		//		+ "                          mapName='address2'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='address3'\n"
		//		+ "                          mapName='address3'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='address4'\n"
		//		+ "                          mapName='address4'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='address5'\n"
		//		+ "                          mapName='address5'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='phone'\n"
		//		+ "                          mapName='phone'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='phone2'\n"
		//		+ "                          mapName='phone2'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		


		//		+ "    <AccountAttributeType name='reissue_cnt'\n"
		//		+ "                          mapName='reissue_cnt'\n"
		//		+ "                          mapType='string'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='apb'\n"
		//		+ "                          mapName='apb'\n"
		//		+ "                          mapType='int'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='reader'\n"
		//		+ "                          mapName='reader'\n"
		//		+ "                          mapType='int'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='active_context'\n"
		//		+ "                          mapName='active_context'\n"
		//		+ "                          mapType='int'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='force_download'\n"
		//		+ "                          mapName='force_download'\n"
		//		+ "                          mapType='int'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		//		+ "    <AccountAttributeType name='facility'\n"
		//		+ "                          mapName='facility'\n"
		//		+ "                          mapType='int'\n"
		//		+ "                          required='false'>\n"
		//		+ "    </AccountAttributeType>\n"
		+ "  </AccountAttributeTypes>\n"
		+ "  <LoginConfigEntry name='com.waveset.security.authn.WSResourceLoginModule' type='"+"Database Table"+"' displayName='"+RAMessages.RES_LOGIN_MOD_DBTABLE+"'>\n"+
		"    <AuthnProperties>\n"+
		"      <AuthnProperty name='"+Constants.DBTABLE_USER+"' displayName='"+RAMessages.UI_USERID_LABEL+"' formFieldType='text' isId='true'/>\n"+
		"      <AuthnProperty name='"+Constants.DBTABLE_PASSWORD+"' displayName='"+RAMessages.UI_PWD_LABEL+"' formFieldType='password'/>\n"+
		"    </AuthnProperties>\n"+
		"    <SupportedApplications>\n"+
		"      <SupportedApplication name='"+Constants.ADMINCONSOLE+"'/>\n"+
		"      <SupportedApplication name='"+Constants.SELFPROVISION+"'/>\n"+
		"    </SupportedApplications>\n"+
		"  </LoginConfigEntry>\n"+
		"  <ResourceUserForm>\n"+
		"    <ObjectRef id='"+Constants.ID_PREFIX+Constants.TOP_ID+"' type='"+Constants.OBJECT_GROUP_TYPE+"'/>\n"+
		"  </ResourceUserForm>\n"+
		"</Resource>\n";
	private HashMap _nativeTimestampsMap;

	public InformixDBResourceAdapter()
	{
		this._util = null;

		this._nativeTimestampsMap = null;
	}

	public static Resource staticCreatePrototypeResource()
	throws WavesetException
	{
		Resource res = new Resource(prototypeXml);

		res.setResourceAttributeVal("correlationRule", null);

		res.setResourceAttributeVal("confirmationRule", null);

		return res;
	}

	public Resource createPrototypeResource() throws WavesetException {
		return staticCreatePrototypeResource();
	}

	public void startConnection()
	throws WavesetException
	{
	}

	public void stopConnection()
	throws WavesetException
	{
	}

	private String getPassword(WSUser user)
	{
		if (user == null) return null;

		String password = null;
		ResourceInfo resInfo = user.getResourceInfo(this._resource);
		if (resInfo != null) {
			EncryptedData ePassword = resInfo.getPassword();
			if (ePassword != null) {
				password = ePassword.decryptToString();
			}
		}

		return password;
	}

	public WavesetResult checkCreateAccount(WSUser user)
	throws WavesetException
	{
		return new WavesetResult();
	}

	public static int getInt(String s) {
		int val =0;
		String EMPTY_STRING = "";
		if ((s != null) && (!s.trim().equals(EMPTY_STRING)))
		{
			try {
				val = Integer.parseInt(s);
			}catch (NumberFormatException nx) {
				nx.printStackTrace();
			}
		}
		return val;
	}

	public static Person parseToPerson(WSUser user)
	{
		Person person = null;
		PersonUser personUser=null;
		if(user!=null)
		{
			Date date=new Date();
			// from Date to long
			Long currentTime=new Long(date.getTime());
			Integer time = Integer.valueOf(currentTime.intValue()); 

			person = new Person();
			personUser= new PersonUser();
			//parsing starting form here 
			person.setFirst_name(user.getAttribute("firstname"));
			person.setLast_name(user.getAttribute("lastname"));
			person.setInitials(user.getAttribute("initials"));
			person.setEmployee(user.getAttribute("employee"));
			person.setTitle(user.getAttribute("title"));
			person.setType(getInt(user.getAttribute("type")));
			person.setDepartment(getInt(user.getAttribute("department")));

			personUser.setSlot_number(getInt(user.getAttribute("SlotNumber")));
			person.setFacility(getInt(user.getAttribute("facility")));



			//person.setFirst_name(user.getAttribute("person_trace"));
			//person.setFirst_name(user.getAttribute("person_trace_alarm"));
			//person.setAddress1(user.getAttribute("address1"));
			//person.setAddress2(user.getAttribute("address2"));
			//person.setAddress3(user.getAttribute("address3"));
			//person.setAddress4(user.getAttribute("address4"));
			//person.setAddress5(user.getAttribute("address5"));
			//person.setPhone(user.getAttribute("phone"));
			//person.setPhone2(user.getAttribute("phone2"));
			//person.setType(getInt(user.getAttribute("type")));

			/*
			person.setStatus(user.getAttribute("status"));
			person.setType(user.getAttribute("type"));
			person.setApb(user.getAttribute("apb"));
			person.setFacility(user.getAttribute("facility"));
			person.setDepartment(user.getAttribute("department"));
			 */
			/*
			person.setAccess_date(user.getAttribute("active_date"));
			person.setAccess_time(access_time)(user.getAttribute("active_time"));
			person.setModify_date(user.getAttribute("modify_date"));
			person.setModify_time(user.getAttribute("modify_time"));
			 */




			person.setAccess_date(time.intValue());
			person.setAccess_time(time.intValue());
			person.setModify_date(time.intValue());
			person.setModify_time(time.intValue());


		}
		return person;
	}


	
	
	public static void readImageFromDatabase() throws Exception
	{
		// Create the SQL command.
		//String commandString = "select * from images where person_id=200698";
		//String commandString = "select * from images where person_id=290418";
		//String commandString = "select * from images where person_id=305755";
		
		String commandString = "select * from images where person_id=7000";
		
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlstmt = null;
		try {
			con = getLocalConnection();
			// Retrieve the results from the database.
			sqlstmt = con.createStatement();

			ResultSet resultSet = sqlstmt.executeQuery(commandString.toString());
			// Check there was a matching record found from the database and throw an exception if no record was found.
			// Move to the first record.
			resultSet.next();

			// The document is stored in byte form in the FileContent column.
			// Retrieve these bytes of the first matching record to a new buffer.
			byte[] buffer = resultSet.getBytes("image_data");

			// Wrap the bytes from the buffer into a new ByteArrayInputStream object.
			ByteArrayInputStream newStream = new ByteArrayInputStream(buffer);

			//ByteArrayInputStream byteArrayInputStream = sysObj.getContent();
			String outStr=newStream.toString();

			File newFile=new File("c:\\chris.jpg");
			FileOutputStream fos = new FileOutputStream(newFile);
			int data; 
			while((data=newStream.read())!=-1)
			{ 
				char ch = (char)data;
				fos.write(ch);
			}
			fos.flush();
			fos.close();


			// Read the document from the input stream.
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error while inseting person Data");
			e.printStackTrace();
		}
		finally {
			//closeResult(res);
			closestatement(sqlstmt);
			closeLocalConnection(con);
		}

	}
	
	
	public static ByteArrayOutputStream getFileBytes() throws IOException {
	    ByteArrayOutputStream ous = null;
	    InputStream ios = null;
	    try {
	    	File file=new File("c:\\cristiano.jpg");
	    	
	        byte[] buffer = new byte[4096];
	        ous = new ByteArrayOutputStream();
	        ios = new FileInputStream(file);
	        int read = 0;
	        while ((read = ios.read(buffer)) != -1)
	            ous.write(buffer, 0, read);
	    } finally {
	        try {
	            if (ous != null)
	                ous.close();
	        } catch (IOException e) {
	            // swallow, since not that important
	        }
	        try {
	            if (ios != null)
	                ios.close();
	        } catch (IOException e) {
	            // swallow, since not that important
	        }
	    }
	    return ous;
	}
	
	
	public static void storeImageToDatabase() throws Exception
	{
		// Create the SQL command.
		//String commandString = "select * from images where person_id=200698";
		//String commandString = "select * from images where person_id=290418";
		String commandString = "insert into  images (person_id,image_data) values (?,?)";

		// Save the document to a OutputStream object.
		ByteArrayOutputStream outputStream = getFileBytes();

		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		PreparedStatement  sqlstmt = null;
		try {
			con = getLocalConnection();
			// Retrieve the results from the database.
			sqlstmt = con.prepareStatement(commandString);

			// Add the parameter value for FileName.
			sqlstmt.setInt(1, 7000);

			// Add the parameter value for FileContent.
			sqlstmt.setBinaryStream(2, new ByteArrayInputStream(outputStream.toByteArray()), outputStream.size());
			 sqlstmt.execute();


		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error while inseting person Data");
			e.printStackTrace();
		}
		finally {
			//closeResult(res);
			closeprestatement(sqlstmt);
			closeLocalConnection(con);
		}

	}
	
	

	public static void createNewCard(Person person)
	{
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlstmt = null;
		try {
			con = getLocalConnection();
			stmt.append("insert into person (pin, status, type, employee, department,first_name, last_name, initials, title, address1, address2, address3, address4,address5, phone, phone2, apb, active_date, active_time, active_context, deactive_date, deactive_time, deactive_context, facility, modify_date, modify_time, force_download, person_kp_resp) values ");
			stmt.append("( (select max(id)+1 from person), 1, " +person.getType()+",'" + person.getEmployee()+ "'," + person.getDepartment() + "," + "'" + person.getFirst_name() + "', '" + person.getLast_name() + "', '" 
					+ person.getInitials() + "', ' ', ' ', ' ', ' ', ' '," + "' ', ' ', ' ', 0, " + person.getActive_date() + ", " + person.getAccess_time() + ", 0," 
					+ person.getDeactive_date() + ", " + person.getDeactive_time() + ", 0, -1, " + person.getModify_date() + ", " + person.getModify_time() + ", 0, 0)");
			System.out.println("Insert person statment :"+stmt.toString());
			sqlstmt = con.createStatement();
			sqlstmt.executeUpdate(stmt.toString());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error while inseting person Data");
			e.printStackTrace();
		}
		finally {
			//closeResult(res);
			closestatement(sqlstmt);
			closeLocalConnection(con);
		}
	}


	public static void createBadge(Person person)
	{
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlstmt = null;
		try {
			con = getLocalConnection();
			// 			stmt.append("insert into badge (bid, status, person_id, " + "issue_date, issue_time, issue_context, " + "expired_date, expired_time, expired_context, " + "usage_count, bid_format_id, facility, modify_date, modify_time) values " + "(" + myCard.getcardNumber.toString() + ", " + myCard.getStatus.toString() + ", " + idPerson + ", " + myCard.getCreationdate.toString() + ", " + myCard.getCreationtime.toString() + ", 0, " + myCard.getExpirationDate.toString() + ", " + myCard.getExpirationTime.toString() 
			// 					+ ", 0, " + "-1, 1, -1, " + myCard.getCreationdate.toString() + ", " + myCard.getCreationtime.toString() + ")");
			// 			System.out.println("Insert person statment :"+stmt.toString());
			sqlstmt = con.createStatement();
			sqlstmt.executeUpdate(stmt.toString());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error while inseting person Data");
			e.printStackTrace();
		}
		finally {
			closestatement(sqlstmt);
			closeLocalConnection(con);
		}
	}


	public static void createUserField(Person person)
	{
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlstmt = null;
		ArrayList personuserList = person.getPersonUserList();
		PersonUser personuser=null;
		if(personuserList != null && !personuserList.isEmpty())
		{
			try {
				con = getLocalConnection();
				for (int i=0;i<personuserList.size();i++ )
				{
					personuser = (PersonUser)personuserList.get(i);
					stmt.append("insert into person_user (id, description, person_id, slot_number, facility, " + "modify_date, modify_time) values ");
					stmt.append("( ' ', '"+personuser.getDescription()+"',"+personuser.getPerson_id()+","+personuser.getSlot_number()
							+","+personuser.getFacility()+","+personuser.getModify_date()+","+personuser.getModify_time()+" )");
					System.out.println("Insert person User statment :"+stmt.toString());
					sqlstmt = con.createStatement();
					sqlstmt.executeUpdate(stmt.toString());
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("Error while inseting person Data");
				e.printStackTrace();
			}
			finally {
				closeLocalConnection(con);
			}

		}
	}


	public static void addAccess(Person person)
	{
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlstmt = null;
		ArrayList personCategoryList = person.getPersonCategoryList();
		PersonCategory personCategory=null;
		if(personCategoryList != null && !personCategoryList.isEmpty())
		{
			try {
				con = getLocalConnection();
				for (int i=0;i<personCategoryList.size();i++ )
				{
					personCategory = (PersonCategory)personCategoryList.get(i);
					stmt.append("insert into person_category (id, person_id, category_id, slot_number, facility, modify_date, modify_time) values ");
					stmt.append("( (select max(id) + 1 from person_category),"+personCategory.getPerson_id()+","+personCategory.getCategory_id()
							+","+personCategory.getSlot_number()+","+personCategory.getFacility()+","+personCategory.getModify_date()+","+personCategory.getModify_time()+" )");
					System.out.println("Insert person User statment :"+stmt.toString());
					sqlstmt = con.createStatement();
					sqlstmt.executeUpdate(stmt.toString());
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("Error while inseting person Data");
				e.printStackTrace();
			}
			finally {
				closeLocalConnection(con);
			}

		}
	}




	public static void deletePerson(String person_Id)
	{
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlPersonDelstmt = null;
		Statement sqlDelperson_userStmt = null;
		Statement sqlDelPerson_categoryStmt = null;
		try {
			con = getLocalConnection();
			stmt.append(" delete person where pin ='"+person_Id+"'");
			System.out.println("Delete person statment :"+stmt.toString());
			sqlPersonDelstmt = con.createStatement();
			sqlPersonDelstmt.executeUpdate(stmt.toString());
			stmt.delete(0, stmt.length());
			stmt.append(" delete person_user where person_id ='"+person_Id+"'");
			sqlDelperson_userStmt = con.createStatement();
			sqlDelperson_userStmt.executeUpdate(stmt.toString());
			stmt.delete(0, stmt.length());
			stmt.append(" delete person_category where person_id ='"+person_Id+"'");
			sqlDelPerson_categoryStmt = con.createStatement();
			sqlDelPerson_categoryStmt.executeUpdate(stmt.toString());
			System.out.println("Deleted person, person_user and person_category for pin  :"+person_Id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error while inseting person Data");
			e.printStackTrace();
		}
		finally {
			closeLocalConnection(con);
		}
	}





	public static void updateAccess(Person person)
	{
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlstmt = null;
		ArrayList personCategoryList = person.getPersonCategoryList();
		PersonCategory personCategory=null;
		if(personCategoryList != null && !personCategoryList.isEmpty())
		{
			try {
				con = getLocalConnection();
				for (int i=0;i<personCategoryList.size();i++ )
				{
					personCategory = (PersonCategory)personCategoryList.get(i);
					stmt.append("insert into person_category (id, person_id, category_id, slot_number, facility, modify_date, modify_time) values ");
					stmt.append("( (select max(id) + 1 from person_category),"+personCategory.getPerson_id()+","+personCategory.getCategory_id()
							+","+personCategory.getSlot_number()+","+personCategory.getFacility()+","+personCategory.getModify_date()+","+personCategory.getModify_time()+" )");
					System.out.println("Insert person User statment :"+stmt.toString());
					sqlstmt = con.createStatement();
					sqlstmt.executeUpdate(stmt.toString());
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("Error while inseting person Data");
				e.printStackTrace();
			}
			finally {
				closestatement(sqlstmt);
				closeLocalConnection(con);
			}

		}
	}


	public static void updateAccess(PersonCategory personCategory)
	{
		Connection con = null;
		StringBuffer stmt = new StringBuffer();
		Statement sqlstmt = null;
		try {
			con = getLocalConnection();
			stmt.append("insert into person_category (id, person_id, category_id, slot_number, facility, modify_date, modify_time) values ");
			stmt.append("( (select max(id) + 1 from person_category),"+personCategory.getPerson_id()+","+personCategory.getCategory_id()
					+","+personCategory.getSlot_number()+","+personCategory.getFacility()+","+personCategory.getModify_date()+","+personCategory.getModify_time()+" )");
			System.out.println("Insert person User statment :"+stmt.toString());
			sqlstmt = con.createStatement();
			sqlstmt.executeUpdate(stmt.toString());

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error while inseting person Data");
			e.printStackTrace();
		}
		finally {
			closestatement(sqlstmt);
			closeLocalConnection(con);
		}
	}



	public static void closeLocalConnection(Connection con)
	{
		if (con != null) {
			try {
				System.out.print("  Closing down all connections...\n\n");
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void closestatement(Statement stmt)
	{
	try {if (stmt != null) stmt.close();} catch (SQLException e) {}
	}
	public static void closeprestatement(PreparedStatement stmt)
	{
	try {if (stmt != null) stmt.close();} catch (SQLException e) {}
	}

	protected void realCreate(WSUser user, WavesetResult result)
	throws WavesetException
	{
		String METHOD = "realCreate";
		TRACE.entry2("realCreate", "user=" + user);
		String id = getIdentity(user);
		Object rowKeyObj = getRequiredResAttrVal("Key Column");
		String rowPass = getOptionalStringResAttrVal("Password Column");

		System.out.println("realCreate called  1");

		System.out.println("User details printing in here ");

		if (id == null) {
			String msg = "Could not get identity.";
			System.out.println("realCreate called  2");
			WavesetException we = new WavesetException("Could not get identity.", Severity.ERROR);
			TRACE.throwing2("realCreate", we);
			throw we;
		}

		Person p = parseToPerson(user);

		if (p!=null)
		{
			System.out.println("Cretaing user start");
			createNewCard(p);
			createUserField(p);
			System.out.println("Cretaing user end");

		}


		/*
 		if (id == null) {
 			String msg = "Could not get identity.";
 			System.out.println("realCreate called  2");
 			WavesetException we = new WavesetException("Could not get identity.", Severity.ERROR);
 			TRACE.throwing2("realCreate", we);
 			throw we;
 		}

 		ArrayList params = new ArrayList();

 		String keyColumn = rowKeyObj.toString();
 		StringBuffer columns = new StringBuffer();
 		addQuotedName(columns, keyColumn);
 		StringBuffer values = new StringBuffer();
 		values.append("?");
 		params.add(new Param(keyColumn, getResourceDefinedType(keyColumn), id));

 		String userPass = getPassword(user);
 		if ((userPass != null) && (rowPass != null)) {
 			columns.append(", ");
 			addQuotedName(columns, rowPass);
 			values.append(", ?");
 			params.add(new Param(rowPass, Syntax.STRING, userPass));
 		}

 		AccountAttributeType[] attrs = this._resource.getAccountAttributeTypes();
 		for (int i = 0; i < attrs.length; i++) {
 			String attrName = attrs[i].getName();
 			String mapName = attrs[i].getMapName();
 			Syntax syntax = attrs[i].getSyntax();
 			WSAttribute attr = user.getWSAttribute(attrName);
 			if (attr == null)
 			{
 				continue;
 			}

 			// added for CategoryId  
 			if(attr.getName().equalsIgnoreCase("category_id"))
 			{
 				System.out.println("Skipped for create CategoryId ");
 				continue;
 			}

 			if ((Util.equalStrings(mapName, keyColumn)) || (Util.equalStrings(mapName, rowPass)))
 			{
 				continue;
 			}
 			Object value = attr.getValue();

 			Syntax syn = Syntax.findSyntax(attr.getType());
 			if (Syntax.ENCRYPTED.equals(syn)) {
 				if ((value != null) && 
 						((value instanceof EncryptedData))) {
 					value = ((EncryptedData)value).decryptToString();
 				}

 				syntax = Syntax.STRING;
 			}

 			columns.append(", ");
 			addQuotedName(columns, mapName);

 			values.append(", ?");
 			params.add(new Param(mapName, syntax, value));
 		}
 		System.out.println("realCreate called  3");
 		Connection con = null;
 		try {
 			con = getConnection();

 			HashMap columnsNullable = getColumnsNullable(con);

 			Iterator it = columnsNullable.entrySet().iterator();
 			while (it.hasNext()) {
 				Map.Entry col = (Map.Entry)it.next();
 				String nullable = (String)col.getValue();
 				String column = (String)col.getKey();

 				if ((nullable.equalsIgnoreCase("NO")) && (columns.indexOf(column) == -1)) {
 					columns.append(", ");
 					addQuotedName(columns, column);
 					values.append(", ?");

 					Syntax syntax = Syntax.STRING;
 					for (int i = 0; i < attrs.length; i++) {
 						if (column == attrs[i].getMapName()) {
 							syntax = attrs[i].getSyntax();
 							break;
 						}
 					}
 					params.add(new Param(column, syntax, (Object)null));
 				}

 			}
 			System.out.println("realCreate called  4");
 			StringBuffer b = new StringBuffer(64);
 			b.append("insert into ");
 			b.append(getRequiredResAttrVal("Table"));
 			b.append(" ( ");
 			b.append(columns.toString());
 			b.append(" ) values ( ");
 			b.append(values.toString());
 			b.append(" )");

 			if (TRACE.level3("realCreate")) {
 				System.out.println("realCreate called  5");
 				StringBuffer msg = new StringBuffer(96);
 				msg.append("Executing query: ");
 				msg.append(b.toString());
 				TRACE.info(0L, "realCreate", msg.toString());
 			}
 			System.out.println("realCreate called  6");
 			Param[] paramArray = (Param[])(Param[])params.toArray(new Param[0]);

 			System.out.println("Create User query :"+b.toString());

 			execSqlWithParams(id, con, b.toString(), paramArray, columnsNullable);

 			ResourceInfo resInfo = user.getResourceInfo(this._resource);
 			if (resInfo != null) {
 				resInfo.setAccountCreated(true);

 				resInfo.setPassword((EncryptedData)null);
 			}
 		}
 		finally {
 			closeConnection(con);
 		}

 		if (TRACE.level3("realCreate")) {
 			StringBuffer sb = new StringBuffer("InformixDBTableResourceAdapter: Added user '");

 			sb.append(id);
 			sb.append("'");
 			TRACE.info(0L, "realCreate", sb.toString());
 		}

 		TRACE.exit2("realCreate", result);
		 */
	}

	public WavesetResult checkUpdateAccount(WSUser user)
	throws WavesetException
	{
		return new WavesetResult();
	}

	protected void realUpdate(WSUser user, WavesetResult result)
	throws WavesetException
	{
		String METHOD = "realUpdate";
		TRACE.entry2("realUpdate", "user=" + user);
		String id = getIdentity(user);

		ArrayList params = new ArrayList();
		StringBuffer updates = new StringBuffer();
		AccountAttributeType[] attrs = this._resource.getAccountAttributeTypes();
		for (int i = 0; i < attrs.length; i++) {
			WSAttribute wsAttr = user.getWSAttribute(attrs[i].getName());

			// if(attrs0[i].getMapName()!=null && !attrs0[i].getMapName().equalsIgnoreCase("CategoryId"))



			if (wsAttr == null)
			{
				continue;
			}
			// added for CategoryId  
			if(wsAttr.getName().equalsIgnoreCase("category_id"))
			{
				System.out.println("Skipped CategoryId ");
				continue;
			}
			Object value = wsAttr.getValue();

			if (updates.length() > 0) {
				updates.append(", ");
			}
			String columnName = attrs[i].getMapName();
			addQuotedName(updates, columnName);
			updates.append(" = ?");
			params.add(new Param(columnName, attrs[i].getSyntax(), value));
		}

		String accountId = user.getAttribute("ws_newAccountId");
		TRACE.info3("realUpdate", "new accountid = " + accountId);

		if (null != accountId) {
			if (updates.length() > 0) {
				updates.append(", ");
			}
			String keyColumn = getRequiredResAttrVal("Key Column").toString();
			addQuotedName(updates, keyColumn);
			updates.append(" = ?");
			params.add(new Param(keyColumn, getResourceDefinedType(keyColumn), accountId));
		}

		String userPass = getPassword(user);
		String rowPass = getOptionalStringResAttrVal("Password Column");
		if ((userPass != null) && (rowPass != null)) {
			if (updates.length() > 0) updates.append(", ");
			addQuotedName(updates, rowPass);
			updates.append(" = ?");
			params.add(new Param(rowPass, Syntax.STRING, userPass));
		}

		if (updates.length() > 0)
		{
			StringBuffer b = new StringBuffer();
			b.append("update ");
			b.append(getRequiredResAttrVal("Table"));
			b.append(" set ");
			b.append(updates.toString());
			b.append(" where ");
			String keyColumn = getRequiredResAttrVal("Key Column").toString();
			addQuotedName(b, keyColumn);
			b.append(" = ?");
			params.add(new Param(keyColumn, getResourceDefinedType(keyColumn), id));

			Connection con = getConnection();
			try {
				if (TRACE.level3("realUpdate")) {
					StringBuffer msg = new StringBuffer(96);
					msg.append("Executing query: ");
					msg.append(b.toString());
					TRACE.info(0L, "realUpdate", msg.toString());
				}

				HashMap columnsNullable = getColumnsNullable(con);

				Param[] paramArray = (Param[])(Param[])params.toArray(new Param[0]);

				System.out.println("Update User query :"+b.toString());

				execSqlWithParams(id, con, b.toString(), paramArray, columnsNullable);

				ResourceInfo resInfo = user.getResourceInfo(this._resource);
				if (resInfo != null) {
					resInfo.setAccountCreated(true);

					resInfo.setPassword((EncryptedData)null);
					if (null != accountId)
						resInfo.setAccountId(accountId);
				}
			}
			finally
			{
				closeConnection(con);
			}
		}

		if (TRACE.level3("realUpdate")) {
			StringBuffer msg = new StringBuffer("InformixDBTableResourceAdapter: Updated user '");

			msg.append(id);
			msg.append("'");
			TRACE.info(0L, "realUpdate", msg.toString());
		}

		TRACE.exit2("realUpdate", result);
	}

	public WavesetResult checkDeleteAccount(WSUser user)
	throws WavesetException
	{
		return new WavesetResult();
	}

	protected void realDelete(WSUser user, WavesetResult result)
	throws WavesetException
	{
		String METHOD = "realDelete";
		TRACE.entry2("realDelete", "user=" + user);
		String id = getIdentity(user);
		System.out.println("---------------> Real delete is called ");
		StringBuffer b = new StringBuffer();
		b.append("delete from ");
		b.append(getRequiredResAttrVal("Table"));
		b.append(" where ");
		String keyColumn = getRequiredResAttrVal("Key Column").toString();
		addQuotedName(b, keyColumn);
		b.append(" = ?");
		System.out.println("---------------> delete query :"+b.toString());
		Param[] paramArray = new Param[1];
		paramArray[0] = new Param(keyColumn, getResourceDefinedType(keyColumn), id);

		Connection con = getConnection();
		try
		{
			if (TRACE.level3("realDelete")) {
				StringBuffer msg = new StringBuffer(96);
				msg.append("Executing query: ");
				msg.append(b.toString());
				TRACE.info(0L, "realDelete", msg.toString());
			}
			System.out.println("Delete  User query :"+b.toString());
			execSqlWithParams(id, con, b.toString(), paramArray);
		}
		finally {
			closeConnection(con);
		}

		if (TRACE.level3("realDelete")) {
			StringBuffer msg = new StringBuffer("Deleted user '");
			msg.append(id);
			msg.append("'");
			TRACE.info(0L, "realDelete", msg.toString());
		}

		TRACE.exit2("realDelete", result);
	}

	public WSUser getUser(WSUser idUser)
	throws WavesetException
	{
		String METHOD = "getUser(WSUser)";
		TRACE.entry1("getUser(WSUser)", "idUser=" + idUser);
		WSUser user = null;

		Connection con = getConnection();
		try {
			user = getUser(con, getIdentity(idUser));
		}
		finally {
			closeConnection(con);
		}

		TRACE.exit1("getUser(WSUser)", user);
		return user;
	}

	
	private WSUser getUser(Connection con, String id)
	throws WavesetException
	{
		WSUser user = null;
		PreparedStatement st = null;
		ResultSet res = null;
		System.out.println("getUser called 1");
		try
		{

			String newstmtstrt="select id,first_name,last_name,initials,department,employee,type from person where id = ?";
			//st = con.prepareStatement(b.toString());
			st = con.prepareStatement(newstmtstrt.toString());
			st.setInt(1, Integer.parseInt(id));
			System.out.println("getUser called 2");
			res = st.executeQuery();
			if (res.next()) {
				user = new WSUser();
				user.setName(id);
				// populating values into 
				user.setAttribute("firstname",res.getString("first_name"));
				user.setAttribute("lastname",res.getString("last_name"));
				user.setAttribute("initials",res.getString("initials"));
				user.setAttribute("employee",res.getString("employee"));
				//user.setAttribute("title",res.getString("firstname"));
				user.setAttribute("type",res.getString("type"));
				user.setAttribute("department",res.getString("department"));
				System.out.println("getUser called 3");
			}
		}
		catch (SQLException e) {
			TRACE.throwing1("getUser(Connection, String)", e);
			throw new InternalError(e);
		}
		finally {
			closeResult(res);
			closeStatement(st);
		}

		if ((user != null) && (user.getAccountId() == null)) {
			user.setAccountId(user.getName());
		}
		TRACE.exit(0L, "getUser(Connection, String)", user);
		return user;
	}
	
	
	private WSUser getUserReal(Connection con, String id)
	throws WavesetException
	{
		String METHOD = "getUser(Connection, String)";
		TRACE.entry2("getUser(Connection, String)");
		if (TRACE.level2("getUser(Connection, String)")) {
			StringBuffer sb = new StringBuffer(48);
			sb.append("con=");
			sb.append(getConnectionString(con));
			sb.append(",id=");
			sb.append(id);
			TRACE.info2("getUser(Connection, String)", sb.toString());
		}

		WSUser user = null;

		PreparedStatement st = null;
		ResultSet res = null;

		StringBuffer b = new StringBuffer();

		b.append("select ");

		Resource resource0 = getResource();
		AccountAttributeType[] attrs0 = resource0.getAccountAttributeTypes();
		int flag=0;
		for (int i = 0; i < attrs0.length; i++) {
			System.out.println("Map name :"+attrs0[i].getMapName());
			flag=1;
			if((attrs0[i].getMapName()!=null && !attrs0[i].getMapName().equalsIgnoreCase("slot_number")) 
					&& (attrs0[i].getMapName()!=null && !attrs0[i].getMapName().equalsIgnoreCase("facility"))	
			)
			{
				addQuotedName(b, attrs0[i].getMapName());
			}
			else 
			{
				System.out.println("Map name from slot_number & facility table adding select qury skipped");
				flag=0;
			}
			if ((i < attrs0.length - 1)&& (flag==1)) {
				b.append(",");
			}
		}

		b.append(" from ");

		b.append(getRequiredResAttrVal("Table"));
		b.append(" where ");
		String keyColumn = getRequiredResAttrVal("Key Column").toString();
		addQuotedName(b, keyColumn);
		b.append(" = ?");
		try
		{
			if (TRACE.level3("getUser(Connection, String)")) {
				StringBuffer msg = new StringBuffer("Executing query: ");
				msg.append(b.toString());
				msg.append(" (for id = " + id + ")");
				TRACE.info(0L, "getUser(Connection, String)", msg.toString());
			}

			//System.out.println("getUser select query :"+b.toString());
			String newstmtstrt="select id,first_name,last_name,initials,department,employee,type from person where id = ?";
			//st = con.prepareStatement(b.toString());
			st = con.prepareStatement(newstmtstrt.toString());
//			Syntax syntaxKeyColumn = getResourceDefinedType(keyColumn);
//			if (Syntax.INT.equals(syntaxKeyColumn)) {
//				int integerValue = 0;
//				try {
//					integerValue = Integer.parseInt(id);
//				} catch (NumberFormatException e) {
//					String msg = "Number Format Exception : " + id + " is not a number.";
//					WavesetException we = new WavesetException(msg, Severity.ERROR);
//					TRACE.throwing2("getUser(Connection, String)", we);
//					throw we;
//				}
//				st.setInt(1, integerValue);
//			} else {
//				st.setString(1, id);
//			}
			
			//st.setString(1, id);
			
			st.setInt(1, Integer.parseInt(id));
			
			res = st.executeQuery();
			if (res.next()) {
				user = new WSUser();
				user.setName(id);

				ResourceInfo info = new ResourceInfo();
				info.setResource(this._resource);
				info.setAccountID(id);
				user.addResourceInfo(info);

				Resource resource = getResource();
				AccountAttributeType[] attrs = resource.getAccountAttributeTypes();
				for (int i = 0; i < attrs.length; i++) {
					Syntax syntax = attrs[i].getSyntax();
					Object val = null;
					if (Syntax.BINARY.equals(syntax))
					{
						byte[] bytes = null;
						Object binaryObj = res.getObject(attrs[i].getMapName());
						if (binaryObj != null) {
							bytes = getBytesFromObject(attrs[i].getMapName(), binaryObj);
						}

						if (bytes != null)
							//val = new Binary(bytes);
						//val = new Binary(bytes);
							val = bytes;
					}
					else {
						String attrMapName = attrs[i].getMapName();
						val = res.getString(attrMapName);
						if (checkNativeTimestamps(resource, res))
						{
							String mapVal = (String)this._nativeTimestampsMap.get(attrMapName);
							if ((mapVal != null) && (mapVal.equals("TIMESTAMP")))
							{
								Object ts = res.getTimestamp(attrMapName);
								val = ts != null ? ts.toString() : null;
							}
						}

						val = Syntax.convertValue(syntax, val);
					}
					if (val != null) {
						WSAttribute wsAttr = new WSAttribute(attrs[i].getName(), val, syntax);
						user.setWSAttribute(wsAttr);
					}
				}
			}
		}
		catch (SQLException e) {
			TRACE.throwing1("getUser(Connection, String)", e);
			throw new InternalError(e);
		}
		finally {
			closeResult(res);
			closeStatement(st);
		}

		if ((user != null) && (user.getAccountId() == null)) {
			user.setAccountId(user.getName());
		}
		TRACE.exit(0L, "getUser(Connection, String)", user);

		return user;
	}

	protected byte[] getBytesFromObject(String columnName, Object binaryObj)
	throws SQLException, InternalError, WavesetException
	{
		byte[] bytes = null;
		if (binaryObj != null)
		{
			if ((binaryObj instanceof byte[])) {
				bytes = (byte[])(byte[])binaryObj;
			}
			else
			{
				InputStream in = null;
				if (OracleLobUtil.isOracleBlob(binaryObj)) {
					in = OracleLobUtil.getBlobBinaryStream(binaryObj);
				}
				else if (OracleLobUtil.isOracleClob(binaryObj)) {
					in = OracleLobUtil.getClobBinaryStream(binaryObj);
				}
				else if ((binaryObj instanceof Blob)) {
					in = ((Blob)binaryObj).getBinaryStream();
				}
				else {
					String className = binaryObj.getClass().getName();
					throw new WavesetException("Unknown conversion for binary column " + columnName + " from instance of " + className + " to byte[]", Severity.ERROR);
				}

				bytes = Util.readInputStreamBytes(in, true);
			}
		}
		return bytes;
	}

	protected void setBinaryParam(PreparedStatement statement, int statementIndex, byte[] value)
	throws SQLException
	{
		statement.setBytes(statementIndex, value);
	}

	public WavesetResult authenticate(HashMap loginInfo)
	throws WavesetException
	{
		String METHOD = "authenticate";
		TRACE.entry1("authenticate");
		if (TRACE.level1("authenticate")) {
			StringBuffer sb = new StringBuffer(32);
			sb.append("loginInfo=");
			sb.append(loginInfo);
			TRACE.entry1("authenticate", sb.toString());
		}

		WavesetResult result = new WavesetResult();

		String accountId = (String)loginInfo.get("db_user");
		EncryptedData password = (EncryptedData)loginInfo.get("db_password");

		String table = (String)getRequiredResAttrVal("Table");
		String passCol = (String)getRequiredResAttrVal("Password Column");

		if ((accountId == null) || (password == null)) {
			WavesetException we = new WavesetException("Missing required login info.", Severity.ERROR);

			TRACE.throwing1("authenticate", we);
			throw we;
		}

		PreparedStatement st = null;
		ResultSet res = null;

		StringBuffer b = new StringBuffer();
		b.append("select ");
		addQuotedName(b, passCol);
		b.append(" from ");
		b.append(table);
		b.append(" where ");
		String keyColumn = getRequiredResAttrVal("Key Column").toString();
		addQuotedName(b, keyColumn);
		b.append(" = ");
		addAttributeValue(b, accountId, keyColumn);

		Connection con = getConnection();
		try {
			if (TRACE.level3("authenticate")) {
				StringBuffer msg = new StringBuffer(96);
				msg.append("Executing query: ");
				msg.append(b.toString());
				TRACE.info(0L, "authenticate", msg.toString());
			}

			st = con.prepareStatement(b.toString());
			res = st.executeQuery();
			if (res.next()) {
				String official = res.getString(passCol);

				if (official == null) {
					WavesetException we = new WavesetException("com.waveset.adapter.RAMessages:LG_INVALID_CREDENTIALS", Severity.ERROR);

					TRACE.throwing1("authenticate", we);
					throw we;
				}

				official = official.trim();
				if (!official.equals(password.decryptToString())) {
					WavesetException we = new WavesetException("com.waveset.adapter.RAMessages:LG_INVALID_CREDENTIALS", Severity.ERROR);

					TRACE.throwing1("authenticate", we);
					throw we;
				}

				result.addResult("AUTHENTICATED_IDENTITY", accountId);
			}
			else {
				WavesetException we = new WavesetException("com.waveset.adapter.RAMessages:LG_INVALID_CREDENTIALS", Severity.ERROR);

				TRACE.throwing1("authenticate", we);
				throw we;
			}
		}
		catch (SQLException e) {
			TRACE.throwing1("authenticate", e);
			throw new InternalError(e);
		}
		finally {
			closeResult(res);
			closeStatement(st);
		}

		TRACE.exit1("authenticate", result);

		return result;
	}

	public WavesetResult testConfiguration() throws WavesetException {
		String METHOD = "testConfiguration";
		TRACE.entry1("testConfiguration");
		System.out.println("testConfiguration --------:1" );
		WavesetResult result = new WavesetResult();

		Connection con = null;
		try {
			ResourceAdapterBase.getRequiredResAttrVal(this._resource, "Key Column");
			System.out.println("testConfiguration --------:2" );
			con = getConnection();
			System.out.println("testConfiguration --------:3" );
			System.out.println("testConfiguration --------:4"+(String)getRequiredResAttrVal("Table") );
			DBTableUtil.checkAccess(con, (String)getRequiredResAttrVal("Table"));
		}
		catch (Throwable t) {
			TRACE.info1("testConfiguration", t.getMessage());
			result.addException(t);
		}
		finally {
			if (con != null) {
				closeConnection(con);
			}
		}

		if (getResource().isActiveSync())
		{
			WavesetResult activeSyncResult = activeSyncTestConfiguration();
			result.assimilate(activeSyncResult);
		}

		TRACE.exit1("testConfiguration", result);
		return result;
	}

	protected void execSqlWithParams(String id, Connection con, String stmt, Param[] params)
	throws WavesetException
	{
		HashMap columnsNullable = getColumnsNullable(con);
		execSqlWithParams(id, con, stmt, params, columnsNullable);
	}

	protected void execSqlWithParams(String id, Connection con, String stmt, Param[] params, HashMap columnsNullable)
	throws WavesetException
	{
		execSqlWithParams(id, con, stmt, params, columnsNullable, 0);
	}

	protected void execSqlWithParams(String id, Connection con, String stmt, Param[] params, HashMap columnsNullable, int ignoreError)
	throws WavesetException
	{
		if (OracleLobUtil.usingOracleJDBC(con)) {
			execOracleSqlWithParams(id, con, stmt, params, columnsNullable, ignoreError);
		}
		else
			execStandardSqlWithParams(id, con, stmt, params, columnsNullable, ignoreError);
	}

	protected void execStandardSqlWithParams(String id, Connection con, String stmt, Param[] params, HashMap columnsNullable, int ignoreError)
	throws WavesetException
	{
		String METHOD = "execStandardSqlWithParams";
		TRACE.entry2("execStandardSqlWithParams");
		if (TRACE.level2("execStandardSqlWithParams")) {
			StringBuffer sb = new StringBuffer(64);
			sb.append("\nconnection=");
			sb.append(getConnectionString(con));
			sb.append("\nstatement=");
			sb.append(stmt);
			for (int i = 0; (params != null) && (i < params.length); i++) {
				sb.append("\narg[" + (i + 1) + "]=");
				sb.append(params[i].value);
				sb.append(" [syntax=");
				sb.append(params[i].syntax);
				sb.append("]");
			}
			sb.append("\nignoreError=");
			sb.append(ignoreError);
			TRACE.info2("execStandardSqlWithParams", sb.toString());
		}

		PreparedStatement s = null;
		try
		{
			s = con.prepareStatement(stmt);
			if ((params != null) && (params.length > 0)) {
				for (int i = 0; i < params.length; i++) {
					Param param = params[i];

					if (param == null)
						continue;
					boolean nullable = true;
					if (columnsNullable.containsKey(param.colName)) {
						String colInfo = (String)columnsNullable.get(param.colName);
						nullable = !colInfo.equalsIgnoreCase("NO");
					}

					if (Syntax.BINARY.equals(param.syntax)) {
						if (param.value != null) {
							Binary binary = (Binary)param.value;
							if (!binary.isNull()) {
								byte[] bytes = binary.toDecodedByteArray();
								setBinaryParam(s, i + 1, bytes);
							}
							else {
								s.setBytes(i + 1, null);
							}
						} else {
							s.setBytes(i + 1, null);
						}
					}
					else if (Syntax.INT.equals(param.syntax)) {
						if (param.value != null) {
							Integer iObj = (Integer)Syntax.convertValue(param.syntax, param.value);
							s.setInt(i + 1, iObj.intValue());
						} else {
							s.setNull(i + 1, 4);
						}
					}
					else if (Syntax.BOOLEAN.equals(param.syntax)) {
						if (param.value != null) {
							Boolean bObj = (Boolean)Syntax.convertValue(param.syntax, param.value);
							s.setBoolean(i + 1, bObj.booleanValue());
						} else {
							s.setNull(i + 1, 16);
						}
					}
					else if (param.value != null) {
						s.setString(i + 1, param.value.toString());
					}
					else if (nullable) {
						s.setString(i + 1, null);
					}
					else {
						String empty = "";
						s.setString(i + 1, empty);
					}

				}

			}

			s.execute();
			flushResults(stmt, s);
		}
		catch (SQLException e) {
			Resource resource = getResource();
			Object value = null;
			if (resource != null) {
				value = resource.getResourceAttributeVal("rethrowAllSQLExceptions");
			}
			boolean throwIt = (value != null) && (((Boolean)value).booleanValue());

			int code = e.getErrorCode();
			if ((throwIt) || (code != ignoreError)) {
				TRACE.throwing2("execStandardSqlWithParams", e);
				throw new InternalError(e);
			}
			if (TRACE.level3("execStandardSqlWithParams"))
				TRACE.info(0L, "execStandardSqlWithParams", e.getMessage());
		}
		finally
		{
			closeStatement(s);
		}
		TRACE.exit2("execStandardSqlWithParams");
	}

	protected void execOracleSqlWithParams(String id, Connection con, String stmt, Param[] params, HashMap columnsNullable, int ignoreError)
	throws WavesetException
	{
		String METHOD = "execOracleSqlWithParams";
		TRACE.entry2("execOracleSqlWithParams");
		if (TRACE.level2("execOracleSqlWithParams")) {
			StringBuffer sb = new StringBuffer(64);
			sb.append("\nconnection=");
			sb.append(getConnectionString(con));
			sb.append("\nstatement=");
			sb.append(stmt);
			for (int i = 0; (params != null) && (i < params.length); i++) {
				sb.append("\narg[" + (i + 1) + "]=");
				sb.append(params[i].value);
				sb.append(" [syntax=");
				sb.append(params[i].syntax);
				sb.append("]");
			}
			sb.append("\nignoreError=");
			sb.append(ignoreError);
			TRACE.info2("execOracleSqlWithParams", sb.toString());
		}

		boolean needLobPass = false;
		PreparedStatement s = null;
		ResultSet rs = null;

		List lobInfo = new ArrayList();
		try
		{
			con.setAutoCommit(false);

			s = con.prepareStatement(stmt);
			if ((params != null) && (params.length > 0)) {
				for (int i = 0; i < params.length; i++) {
					Param param = params[i];
					if (param == null)
						continue;
					boolean nullable = true;
					if (columnsNullable.containsKey(param.colName)) {
						String colInfo = (String)columnsNullable.get(param.colName);
						nullable = !colInfo.equalsIgnoreCase("NO");
					}
					if (Syntax.BINARY.equals(param.syntax))
					{
						if (param.value != null) {
							Binary binary = (Binary)param.value;
							if (!binary.isNull()) {
								int binaryColType = getColumnType(con, param.colName);
								if (2004 == binaryColType) {
									Map details = new HashMap();
									details.put("type", new Integer(binaryColType));
									details.put("param", param);
									lobInfo.add(details);
									needLobPass = true;
									s.setBlob(i + 1, OracleLobUtil.getEmptyBlob());
								}
								else if (2005 == binaryColType) {
									Map details = new HashMap();
									details.put("type", new Integer(binaryColType));
									details.put("param", param);
									lobInfo.add(details);
									needLobPass = true;
									s.setClob(i + 1, OracleLobUtil.getEmptyClob());
								}
								else {
									byte[] bytes = binary.toDecodedByteArray();
									s.setBytes(i + 1, bytes);
								}
							}
							else {
								s.setBytes(i + 1, null);
							}
						} else {
							s.setBytes(i + 1, null);
						}
					}
					else if (Syntax.INT.equals(param.syntax)) {
						if (param.value != null) {
							Integer iObj = (Integer)Syntax.convertValue(param.syntax, param.value);
							s.setInt(i + 1, iObj.intValue());
						} else {
							s.setNull(i + 1, 4);
						}
					}
					else if (Syntax.BOOLEAN.equals(param.syntax)) {
						if (param.value != null) {
							Boolean bObj = (Boolean)Syntax.convertValue(param.syntax, param.value);
							s.setBoolean(i + 1, bObj.booleanValue());
						}
						else
						{
							s.setString(i + 1, null);
						}
					}
					else if (param.value != null) {
						s.setString(i + 1, param.value.toString());
					}
					else if (nullable) {
						s.setString(i + 1, null);
					} else {
						String empty = "";
						s.setString(i + 1, empty);
					}

				}

			}

			s.execute();
			closeStatement(s);
			s = null;

			if (needLobPass)
			{
				StringBuffer columns = new StringBuffer();

				for (int i = 0; i < lobInfo.size(); i++) {
					Map details = (Map)lobInfo.get(i);
					Param param = (Param)details.get("param");
					if (i > 0) {
						columns.append(",");
					}
					addQuotedName(columns, param.colName);
				}

				String sql = "SELECT " + columns.toString() + " from " + getRequiredResAttrVal("Table") + " WHERE " + getRequiredResAttrVal("Key Column") + " = ? FOR UPDATE";

				s = con.prepareStatement(sql);
				s.setString(1, id);
				rs = s.executeQuery();
				rs.next();

				StringBuffer setClause = new StringBuffer();
				setClause.append("SET ");

				for (int i = 0; i < lobInfo.size(); i++) {
					Map details = (Map)lobInfo.get(i);
					Param param = (Param)details.get("param");
					if (i > 0) {
						setClause.append(",");
					}
					addQuotedName(setClause, param.colName);
					setClause.append(" = ?");
					Integer type = (Integer)details.get("type");
					if (type.intValue() == 2004) {
						Object blob = rs.getObject(i + 1);
						OutputStream bos = OracleLobUtil.getBlobBinaryOutputStream(blob);
						byte[] bytes = ((Binary)param.value).toDecodedByteArray();
						ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
						try {
							Util.copyFile(bais, bos);

							bos.close();
						}
						catch (IOException e) {
							WavesetException we = new WavesetException(e);
							TRACE.throwing2("execOracleSqlWithParams", we);
							throw we;
						}
						details.put("lob", blob);
					}
					else {
						Object clob = rs.getObject(i + 1);
						OutputStream bos = OracleLobUtil.getClobBinaryOutputStream(clob);
						byte[] bytes = ((Binary)param.value).toDecodedByteArray();
						ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
						try {
							Util.copyFile(bais, bos);

							bos.close();
						}
						catch (IOException e) {
							WavesetException we = new WavesetException(e);
							TRACE.throwing2("execOracleSqlWithParams", we);
							throw we;
						}
						details.put("lob", clob);
					}
				}

				flushResults(sql, s);

				closeResult(rs);
				rs = null;
				closeStatement(s);
				s = null;

				sql = "UPDATE " + getRequiredResAttrVal("Table") + " " + setClause.toString() + " WHERE " + getRequiredResAttrVal("Key Column") + " = ?";

				s = con.prepareStatement(sql);

				for (int i = 0; i < lobInfo.size(); i++) {
					Map details = (Map)lobInfo.get(i);
					Object val = details.get("lob");
					s.setObject(i + 1, val);
				}
				s.setString(lobInfo.size() + 1, id);

				s.executeUpdate();

				flushResults(stmt, s);
			}

			con.commit();
		}
		catch (SQLException e)
		{
			Resource resource = getResource();
			Object value = null;
			if (resource != null) {
				value = resource.getResourceAttributeVal("rethrowAllSQLExceptions");
			}
			boolean throwIt = (value != null) && (((Boolean)value).booleanValue());

			int code = e.getErrorCode();
			if ((throwIt) || (code != ignoreError)) {
				TRACE.throwing2("execOracleSqlWithParams", e);
				throw new InternalError(e);
			}
			if (TRACE.level3("execOracleSqlWithParams"))
				TRACE.info(0L, "execOracleSqlWithParams", e.getMessage());
		}
		finally
		{
			closeResult(rs);
			rs = null;
			closeStatement(s);
			s = null;
		}
		TRACE.exit2("execOracleSqlWithParams");
	}

	private HashMap getColumnsNullable(Connection con)
	throws WavesetException
	{
		Resource resource = getResource();
		AccountAttributeType[] attrs = resource.getAccountAttributeTypes();

		HashMap nullables = new HashMap();
		for (int i = 0; i < attrs.length; i++)
		{
			nullables.put(attrs[i].getMapName(), "");
		}

		Boolean empty = getOptionalBooleanResAttrVal("enableEmptyString");
		if (!empty.booleanValue()) {
			return nullables;
		}

		ResultSet res = null;
		try
		{
			String table = (String)getRequiredResAttrVal("Table");
			res = con.getMetaData().getColumns(null, null, table, null);

			if (res != null)
				while (res.next()) {
					String colName = res.getString("column_name");

					if ((colName == null) || (!nullables.containsKey(colName))) {
						continue;
					}
					String nullable = res.getString("is_nullable");
					nullables.put(colName, nullable);
				}
		}
		catch (SQLException e)
		{
			throw new WavesetException(e);
		}
		finally {
			closeResult(res);
			res = null;
		}
		return nullables;
	}
	private int getColumnType(Connection con, String columnName) throws WavesetException {
		ResultSet rs = null;
		PreparedStatement st = null;
		int sqlType;
		try { st = con.prepareStatement("SELECT " + columnName + " FROM " + getRequiredResAttrVal("Table") + " WHERE " + getRequiredResAttrVal("Key Column") + "=NULL");

		rs = st.executeQuery();
		sqlType = rs.getMetaData().getColumnType(1);
		} catch (SQLException e)
		{
			throw new WavesetException(e);
		}
		finally {
			closeResult(rs);
			rs = null;
			closeStatement(st);
			st = null;
		}
		return sqlType;
	}

	public AccountIterator getAccountIterator()
	throws WavesetException
	{
		System.out.println("Account iterator called -1 ");
		return getAccountIterator(null);
	}



	public AccountIterator getAccountIterator(Map searchParams) throws WavesetException
	{
		String METHOD = "getAccountIterator";

		TRACE.entry1("getAccountIterator");
		if (TRACE.level1("getAccountIterator")) {
			String msg = null;
			if (searchParams != null) {
				msg = searchParams.toString();
			}
			TRACE.info1("getAccountIterator", msg);
		}

		Connection con = getConnection();
		AccountIterator acctIter = new DatabaseTableAccountIterator(con, this, searchParams);

		TRACE.exit1("getAccountIterator", acctIter);

		return acctIter;
	}

	public GenericObject getFeatures()
	{
		GenericObject result = super.getFeatures();

		Resource resource = getResource();
		if (resource != null)
		{
			Object value = resource.getResourceAttributeVal("noPasswords");
			if ((value != null) && (((Boolean)value).booleanValue()))
			{
				result.remove("account.PASSWORD");
			}
		}

		result.put("account.BINARY", "account.BINARY");
		result.put("account.RENAME", "account.RENAME");

		return result;
	}

	public void init()
	throws Exception
	{
		String METHOD = "init";
		TRACE.entry1("init");

		this._util = new ActiveSyncUtil(getResource(), this);
		traceAndLog(1L, "init", 2, "Initializing DatabaseTable resource adapter.\n");

		traceAndLog(1L, "init", 2, this._resource.toXml());
		traceAndLog(1L, "init", 2, "Done initializing DatabaseTable resource adapter.\n");

		TRACE.exit1("init");
	}

	public void shutdown()
	{
	}

	public Object getAttributeValue(String name)
	throws WavesetException
	{
		return getResource().getResourceAttributeVal(name);
	}

	public void setAttributeValue(String name, Object value)
	throws WavesetException
	{
		getResource().setResourceAttributeVal(name, value);
	}

	public int poll()
	{
		String METHOD = "poll";
		TRACE.entry1("poll");
		StringBuffer tsb = new StringBuffer(48);
		tsb.append("Starting poll for ");
		tsb.append(getResource().getName());
		tsb.append(" resource adapter.\n");
		traceAndLog(1L, "poll", 2, tsb.toString());

		int numProcessed = 0;
		try
		{
			IAPI prox = IAPIFactory.getIAPIProcess(null, null, null, this);
			Map lastProcessedMap = ActiveSyncUtil.reconstituteEmptyStrings((Map)prox.getProperty("lastProcessed"));

			if (TRACE.level1("poll")) {
				StringBuffer sb = new StringBuffer("lastProcessed map = ");
				sb.append(lastProcessedMap);
				TRACE.info(0L, "poll", sb.toString());
			}
			if (this._util.getLogLevel() >= 2) {
				this._util.logInfoMap("lastProcessed", lastProcessedMap);
			}

			UpdateRows updateRows = getUpdatedRows(lastProcessedMap);

			if ((updateRows != null) && (updateRows.getUpdateRows() != null) && (updateRows.getUpdateRows().size() > 0))
			{
				List updates = updateRows.getUpdateRows();
				numProcessed = updates.size();

				processUpdates(updateRows, "update", prox);
			}

			if (numProcessed == 0) {
				traceAndLog(1L, "poll", 2, "Poll found nothing to do");
			}
		}
		catch (Throwable th)
		{
			this._util.logResourceException("Error processing updates", th, TRACE, "poll");
		}

		traceAndLog(1L, "poll", 2, "Completed poll for " + getResource().getName() + " resource adapter.\n");

		TRACE.exit1("poll", numProcessed);

		return numProcessed;
	}

	public void callCompleted(IAPI call)
	{
		this._util.logString(2, "Completed IAPI " + call.toXml());
	}

	UpdateRows getUpdatedRows(Map lastProcessedMap)
	{
		String METHOD = "getUpdatedRows";
		TRACE.entry2("getUpdatedRows");
		if (TRACE.level2("getUpdatedRows")) {
			StringBuffer sb = new StringBuffer(80);
			sb.append("lastProcessedMap=");
			sb.append(lastProcessedMap);
			TRACE.info2("getUpdatedRows", sb.toString());
		}
		List list = new ArrayList();

		UpdateRows updateRows = new UpdateRows(list, new UpdateRow(null, lastProcessedMap));
		try
		{
			HashMap listOptions = new HashMap();

			StringBuffer qualifierBuffer = new StringBuffer();
			String staticSearchPredicate = getOptionalStringResAttrVal("Static Search Predicate");
			String lastFetchedConjunction = getOptionalStringResAttrVal("Last Fetched Conjunction");
			String lastFetchedPredicate = getOptionalStringResAttrVal("Last Fetched Predicate");

			boolean needConj = false;
			if (Util.length(staticSearchPredicate) > 0) {
				qualifierBuffer.append(staticSearchPredicate);
				needConj = true;
			}

			boolean isLastProcessedEmpty = (lastProcessedMap == null) || (lastProcessedMap.size() == 0);
			if ((isLastProcessedEmpty) && (Util.length(lastFetchedPredicate) > 0))
			{
				traceAndLog(1L, "getUpdatedRows", 2, "Last Fetched Predicate ignored this initial poll because there is no lastProcessed property set");
			}

			if ((!isLastProcessedEmpty) && (Util.length(lastFetchedPredicate) > 0))
			{
				String expandedLastFetchedPredicate = VariableExpander.expand(lastFetchedPredicate, new StrictMapResolver(lastProcessedMap));

				if (needConj) {
					qualifierBuffer.append(" ");
					qualifierBuffer.append(lastFetchedConjunction);
					qualifierBuffer.append(" ");
				}
				qualifierBuffer.append(expandedLastFetchedPredicate);
			}

			listOptions.put("searchFilter", qualifierBuffer.toString());

			String orderByClause = getOptionalStringResAttrVal("Order By Clause");
			if (Util.length(orderByClause) > 0) {
				listOptions.put("orderBy", orderByClause);
			}

			if (TRACE.level1("getUpdatedRows")) {
				StringBuffer sb = new StringBuffer(64);
				sb.append("listOptions map = ");
				sb.append(listOptions);
				TRACE.info(0L, "getUpdatedRows", sb.toString());
			}

			if (this._util.getLogLevel() >= 2) {
				this._util.logInfoMap("listOptions", listOptions);
			}

			AccountIterator acctIter = null;
			try {
				acctIter = getAccountIterator(listOptions);

				while ((acctIter.hasNext()) && (!this._util.isStopRequested())) {
					WSUser user = acctIter.next();
					Map userMap = user.toHashMap(true);
					ResourceInfo ri = user.getResourceInfo(getResource());
					if (ri != null) {
						userMap.put("identity", ri.getAccountId());
					}
					list.add(new UpdateRow(null, userMap));
				}
			} finally {
				if (acctIter != null)
					acctIter.close();
			}
		}
		catch (WavesetException ex) {
			this._util.logString(1, Util.stackToString(ex));
		}

		TRACE.exit2("getUpdatedRows", updateRows);
		return updateRows;
	}

	protected IAPI buildEventLegacy(UpdateRow row, String command)
	throws WavesetException, IAPIException
	{
		String METHOD = "buildEvent";
		TRACE.entry2("buildEvent");
		if (TRACE.level2("buildEvent")) {
			StringBuffer sb = new StringBuffer(48);
			sb.append("row=");
			if (row != null)
				sb.append(row.toString());
			else {
				sb.append("null");
			}
			sb.append("command=");
			sb.append(command);
			TRACE.info2("buildEvent", sb.toString());
		}

		Map userMap = row.getUserMap();
		String identity = (String)userMap.get("identity");
		if (identity == null) {
			String msg = "Missing required attribute identity. This is a configuration problem.";

			WavesetException we = new WavesetException("Missing required attribute identity. This is a configuration problem.", Severity.ERROR);
			TRACE.throwing2("buildEvent", we);
			throw we;
		}

		Map options = new HashMap();
		String adminName = (String)userMap.get("AUDIT_OPRID");
		if (adminName != null) {
			options.put("RemoteAdminName", adminName);
		}
		IAPI update = null;

		String processName = getOptionalStringResAttrVal("processRule");
		if (processName != null)
		{
			IAPIProcess process = IAPIFactory.getIAPIProcess(options, userMap, "create", this);

			process.setProcessName(processName);
			update = process;
		}
		else
		{
			update = IAPIFactory.getIAPIUser(options, userMap, command, this);

			List viewIDs = update.find(Attribute.NAME.toString(), identity, 2, false);
			if ((viewIDs == null) || (viewIDs.size() < 1)) {
				viewIDs = update.find(Attribute.RESOURCE_ACCOUNT_IDS.toString(), identity, 2, false);
			}

			if (viewIDs == null)
			{
				if ("update".equals(command)) {
					update.setCommand("create");
					StringBuffer sb = new StringBuffer(64);
					sb.append("Received update for user ");
					sb.append(identity);
					sb.append(" not in Lighthouse. Turning into a create\n");
					traceAndLog(1L, "buildEvent", 2, sb.toString());
				}
			}
			else {
				if (viewIDs.size() > 1) {
					StringBuffer sb = new StringBuffer("Found multiple matches for id ");
					sb.append(userMap.get("name"));
					InternalError ie = new InternalError(sb.toString());

					TRACE.throwing2("buildEvent", ie);
					throw ie;
				}

				update.setViewID((String)viewIDs.get(0));
			}

		}

		update.setLogger(this._util.getLogger());

		TRACE.exit2("buildEvent", update);
		return update;
	}

	protected boolean useLegacyEventGeneration()
	{
		Boolean legacy = getOptionalBooleanResAttrVal("useLegacyEventGeneration");

		return (legacy != null) && (legacy.booleanValue());
	}

	private boolean ignoreEventFailures()
	{
		return getOptionalBooleanResAttrVal("ignoreEventFailures").booleanValue();
	}

	protected void processUpdates(UpdateRows updateRows, String command, IAPI prox)
	throws WavesetException, IAPIException
	{
		String METHOD = "processUpdates";
		TRACE.entry2("processUpdates");
		if (TRACE.level2("processUpdates")) {
			StringBuffer sb = new StringBuffer(64);
			sb.append("updateRows=");
			sb.append(updateRows);
			sb.append("command=");
			sb.append(command);
			sb.append("prox=");
			sb.append(prox);
			TRACE.info2("processUpdates", sb.toString());
		}
		List list = updateRows.getUpdateRows();
		if (list != null) {
			Iterator it = list.iterator();
			for (int i = 0; (it.hasNext()) && (!this._util.isStopRequested()); i++) {
				UpdateRow row = (UpdateRow)it.next();

				traceAndLogCommand(3L, "processUpdates", 2, row, command, null);

				IAPI event = null;
				if (useLegacyEventGeneration()) {
					event = buildEventLegacy(row, command);
				} else {
					Map options = new HashMap();
					Map userMap = row.getUserMap();
					String adminName = (String)userMap.get("AUDIT_OPRID");
					if (adminName != null)
						options.put("RemoteAdminName", adminName);
					event = IAPIFactory.getIAPI(options, userMap, this);
				}

				if (event != null) {
					WavesetResult result = event.submit();

					if (!result.hasError())
					{
						prox.setProperty("lastProcessed", row.getUserMap());
					}
					else if (ignoreEventFailures())
					{
						traceAndLog(3L, "processUpdates", 2, "Updating lastProcessed with current map even though an error was detected");

						prox.setProperty("lastProcessed", row.getUserMap());
					}

					traceAndLogCommand(3L, "processUpdates", 2, row, command, result);
				}
			}

		}

		TRACE.exit1("processUpdates");
	}

	protected void traceAndLogCommand(long traceLevel, String method, int logLevel, UpdateRow update, String command, WavesetResult result)
	{
		if (update == null) {
			return;
		}

		if ((!TRACE.isLogging(traceLevel, method)) && (this._util.getLogLevel() < logLevel))
		{
			return;
		}

		Map audit = update.getAuditMap();
		Map user = update.getUserMap();
		List msgs = result != null ? result.getMessages() : null;
		List errs = result != null ? result.getErrors() : null;

		StringBuffer sb = new StringBuffer();
		if (result == null) {
			sb.append("Starting ");
			sb.append(command);
			sb.append(" processing for resource ");
			sb.append(getResource().getName());
			sb.append('\n');
			if (TRACE.isLogging(traceLevel, method)) {
				TRACE.info(traceLevel, method, sb.toString());
			}
			if (logLevel < this._util.getLogLevel()) {
				this._util.logString(logLevel, sb.toString());
			}
			sb.setLength(0);
		}

		ActiveSyncUtil.mapToStringBuffer(audit, sb);
		ActiveSyncUtil.mapToStringBuffer(user, sb);
		ActiveSyncUtil.listToStringBuffer(errs, sb);
		ActiveSyncUtil.listToStringBuffer(msgs, sb);
		try
		{
			if (TRACE.isLogging(traceLevel, method)) {
				TRACE.info(traceLevel, method, sb.toString());
			}
			if (logLevel < this._util.getLogLevel())
				this._util.logString(logLevel, sb.toString());
		}
		catch (Throwable th) {
			System.out.println("DatabaseTable Resource adapter. Error writing log: " + th.toString());
		}

		if (result != null) {
			sb.setLength(0);
			sb.append("End update processing for resource ");
			sb.append(getResource().getName());
			sb.append('\n');
			if (TRACE.isLogging(traceLevel, method)) {
				TRACE.info(traceLevel, method, sb.toString());
			}
			if (logLevel < this._util.getLogLevel())
				this._util.logString(logLevel, sb.toString());
		}
	}

	public WavesetResult activeSyncTestConfiguration()
	throws WavesetException
	{
		String METHOD = "activeSyncTestConfiguration";
		TRACE.entry1("activeSyncTestConfiguration");
		WavesetResult result = new WavesetResult();
		System.out.println("activeSyncTestConfiguration   started ==================> ");
		String staticSearchFilter = getOptionalStringResAttrVal("Static Search Predicate");
		String lastFetchedFilter = getOptionalStringResAttrVal("Last Fetched Predicate");
		if ((Util.length(staticSearchFilter) == 0) && (Util.length(lastFetchedFilter) == 0)) {
			Message errmsg = new Message("com.waveset.adapter.RAMessages:DBTABLE_SYNC_TESTCONFIG_NO_PREDICATE", "Static Search Predicate", "Last Fetched Predicate");

			TRACE.info3("activeSyncTestConfiguration", errmsg.getMessage());
			result.addWarning(errmsg);
		}

		String lastFetchedConjunction = getOptionalStringResAttrVal("Last Fetched Conjunction");
		if (Util.length(lastFetchedConjunction) > 0) {
			if ((!lastFetchedConjunction.equalsIgnoreCase("AND")) && (!lastFetchedConjunction.equalsIgnoreCase("OR")))
			{
				Object[] parms = { lastFetchedConjunction, "Last Fetched Conjunction" };
				ErrorMessage errmsg = new ErrorMessage(Severity.ERROR, "com.waveset.adapter.RAMessages:DBTABLE_SYNC_TESTCONFIG_BAD_CONJUNCTION", parms);

				TRACE.info3("activeSyncTestConfiguration", errmsg.getMessage());
				result.addError(errmsg);
			}

		}
		else if ((Util.length(staticSearchFilter) > 0) && (Util.length(lastFetchedFilter) > 0)) {
			ErrorMessage errmsg = new ErrorMessage(Severity.ERROR, "com.waveset.adapter.RAMessages:DBTABLE_SYNC_TESTCONFIG_MISSING_ATTR", "Last Fetched Conjunction");

			TRACE.info3("activeSyncTestConfiguration", errmsg.getMessage());
			result.addError(errmsg);
		}

		if (Util.length(lastFetchedFilter) > 0) {
			VariableChecker checker = new VariableChecker(getSchemaMap());
			try {
				VariableExpander.expand(lastFetchedFilter, checker);
			}
			catch (WavesetException e) {
				TRACE.info3("activeSyncTestConfiguration", e.getMessage());
				result.addException(e);
			}
		}
		TRACE.exit1("activeSyncTestConfiguration", result);
		System.out.println("activeSyncTestConfiguration   end <==================");
		return result;
	}

	protected void traceAndLog(long traceLevel, String method, int logLevel, String message)
	{
		TRACE.info(traceLevel, method, message);
		this._util.logString(logLevel, message);
	}

	public void addQuotedName(StringBuffer b, String s)
	{
		String quoting = getOptionalStringResAttrVal("Quoting");
		addQuotedName(b, s, quoting);
	}

	public static void addQuotedName(StringBuffer b, String s, String quoting) {
		if ((b == null) || (s == null))
			return;
		if ((quoting == null) || (quoting.equals("none"))) {
			b.append(s);
		} else if (quoting.equalsIgnoreCase("Double")) {
			b.append("\"");
			b.append(s);

			b.append("\"");
		} else if (quoting.equalsIgnoreCase("Single")) {
			b.append("'");
			b.append(s);
			b.append("'");
		} else if (quoting.equalsIgnoreCase("Back")) {
			b.append("`");
			b.append(s);
			b.append("`");
		} else if (quoting.equalsIgnoreCase("Brackets")) {
			b.append("[");
			b.append(s);
			b.append("]");
		} else {
			b.append(s);
		}
	}



	public static Connection getLocalConnection()
	{
		System.out.println("Informix Connect Example.");
		Connection conn = null;
		//String url = "jdbc:informix-sqli://localhost:9089/proteus:INFORMIXSERVER=ol_ids_1150_1";
		//String url = "jdbc:informix-sqli://pp45linux53:9088/proteus:INFORMIXSERVER=pp45linux53";
		//String url = "jdbc:informix-sqli://142.183.198.129:1960/proteus:INFORMIXSERVER=rideau";
		//String url = "jdbc:informix-sqli://142.183.198.129:1960";
		//String url = "jdbc:informix-sqli://10.154.134.132:9088/proteus:INFORMIXSERVER=INBLRW2137";
		String url = "jdbc:informix-sqli://142.117.22.131:9088/proteus:INFORMIXSERVER=blmcwd";
		String dbName = "proteus";
		String driver = "com.informix.jdbc.IfxDriver";
		//String userName = "CSACIM"; 
		//String password = "CSACIM00";

		//String userName = "informix"; 
		//String password = "informix1";

		// 		String userName = "informix"; 
		// 		String password = "pa$$w0rd";
		String userName = "ppapp"; 
		String password = "bp&&ppapp";
		try {
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(url,userName,password);
			System.out.println("Connected to the database");
			//conn.close();
			System.out.println("Disconnected from database");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}

	
	

	
	public Connection getConnection()
	throws WavesetException
	{

		Connection conn=null;
		String connection =(String)getRequiredResAttrVal(RAMessages.RESATTR_URL_TEMPLATE);
		try {
			Class.forName((String)getRequiredResAttrVal(RAMessages.RESATTR_JDBC_DRIVER));
			conn =DriverManager.getConnection(connection, (String)getRequiredResAttrVal("User"), (String)getEncryptedResourceAttribute("Password"));

		} catch (Exception e) {
			e.printStackTrace();
		}

		return conn;
	}

	private void cleanupConnection(Connection con)
	throws WavesetException
	{
		String METHOD = "cleanupConnection";

		if (con != null)
		{
			boolean isAutoCommit = true;
			try {
				isAutoCommit = con.getAutoCommit();
			} catch (SQLException t) {
				if (TRACE.level2("cleanupConnection")) {
					TRACE.info2("cleanupConnection", "Failed to call getAutoCommit() on " + getConnectionString(con) + ": " + t.toString());
				}

				throw new WavesetException(t);
			}

			if (!isAutoCommit) {
				try {
					con.rollback();
				} catch (SQLException t) {
					if (TRACE.level2("cleanupConnection")) {
						TRACE.info2("cleanupConnection", "Failed to rollback a transacted connection " + getConnectionString(con) + ": " + t.toString());
					}

					throw new WavesetException(t);
				}
				try
				{
					if (TRACE.level4("cleanupConnection")) {
						TRACE.info4("cleanupConnection", "Forcing connection " + getConnectionString(con) + " back to autoCommit(true)");
					}
					con.setAutoCommit(true);
				} catch (SQLException t) {
					if (TRACE.level2("cleanupConnection")) {
						TRACE.info2("cleanupConnection", "Failed to set " + getConnectionString(con) + " auto commit to true: " + t.toString());
					}

					throw new WavesetException(t);
				}
			}
		}
	}

	public void closeConnection(Connection con)
	{
		String METHOD = "closeConnection";

		TRACE.entry1("closeConnection");
		if (con != null) {
			try {
				if (!con.getAutoCommit()) {
					con.rollback();
					con.setAutoCommit(true);
				}
				super.closeConnection(con);
			} catch (SQLException e) {
				if (TRACE.level3("closeConnection")) {
					StringBuffer sb = new StringBuffer();
					sb.append("WARNING: Exception closing JDBC connection.  Will destroy connection instead.");
					sb.append(e.getMessage());
					TRACE.info(0L, "closeConnection", sb.toString());
				}
				destroyConnection(con);
			}
		}
		TRACE.exit1("closeConnection");
	}

	private void destroyConnection(Connection con) {
		String METHOD = "destroyConnection";
		TRACE.entry1("destroyConnection");
		if (TRACE.level1("destroyConnection")) {
			StringBuffer sb = new StringBuffer(48);
			sb.append("connection=");
			sb.append(getConnectionString(con));
			TRACE.info1("destroyConnection", sb.toString());
		}
		try
		{
			if ((con instanceof PooledConnection))
			{
				PooledConnection pc = (PooledConnection)con;
				pc.destroy();
			}
			else
			{
				try
				{
					if (!con.getAutoCommit())
						con.rollback();
				}
				catch (SQLException e)
				{
					TRACE.caught(0L, "destroyConnection", e);
				}

				con.close();
			}
		}
		catch (SQLException e) {
			TRACE.caught(0L, "destroyConnection", e);
		}

		TRACE.exit1("destroyConnection");
	}

	public boolean checkNativeTimestamps(Resource resource, ResultSet rs) throws SQLException
	{
		boolean nativeTimestampsFlag = false;
		if (this._nativeTimestampsMap == null) {
			Object nativeTsVal = resource.getResourceAttributeVal("nativeTimestamps");
			if ((nativeTsVal != null) && (nativeTsVal.toString() != null) && (nativeTsVal.toString().equalsIgnoreCase("true")))
			{
				this._nativeTimestampsMap = new HashMap();
				ResultSetMetaData rsmd = rs.getMetaData();
				int numberOfColumns = rsmd.getColumnCount();
				for (int col = 1; col <= numberOfColumns; col++) {
					if (rsmd.getColumnTypeName(col).indexOf("TIMESTAMP") != -1) {
						this._nativeTimestampsMap.put(rsmd.getColumnName(col), "TIMESTAMP");
					}
				}
				nativeTimestampsFlag = true;
			}
		} else {
			nativeTimestampsFlag = true;
		}
		return nativeTimestampsFlag;
	}

	public HashMap getNativeTimestampsMap() {
		return this._nativeTimestampsMap;
	}

	protected Syntax getResourceDefinedType(String columnName)
	{
		ArrayList params = new ArrayList();
		AccountAttributeType[] attrs = this._resource.getAccountAttributeTypes();
		for (int i = 0; i < attrs.length; i++) {
			String attrName = attrs[i].getMapName();
			Syntax syntax = attrs[i].getSyntax();
			if (columnName.equals(attrName))
				return syntax;
		}
		return Syntax.STRING;
	}


	public static void main(String[] args) {
		System.out.println("Started ");
		//Connection con = null;
		//con = getLocalConnection();
		
	/*	
		Person objperson = new Person();
		objperson.setFirst_name("Joju3");
		objperson.setLast_name("Biju4");
		ArrayList userFieldList = new ArrayList();
		PersonUser personuser = new PersonUser();
		personuser.setSlot_number(20);
		userFieldList.add(personuser);
		objperson.setPersonUserList(userFieldList);

		ArrayList accessList = new ArrayList();
		PersonCategory personCategory = new PersonCategory();
		personCategory.setCategory_id(20);
		accessList.add(personCategory);
		objperson.setPersonCategoryList(accessList);

		createNewCard(objperson);
		createUserField(objperson);
		addAccess(objperson);
*/
		//deletePerson("90");
		
		try {
			readImageFromDatabase() ;
			//storeToDatabase();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println("End ");

	}


	public static class StrictMapResolver
	implements VariableResolver
	{
		Map _map;

		StrictMapResolver(Map map)
		{
			this._map = map;
		}

		public Object resolveVariable(String variable) throws WavesetException
		{
			Object value = this._map.get(variable);

			if ((value == null) && (!this._map.containsKey(variable))) {
				ErrorMessage msg = new ErrorMessage(Severity.ERROR, "com.waveset.adapter.RAMessages:DBTABLE_SYNC_UNKNOWN_VARIABLE", variable);
				throw new WavesetException(msg);
			}

			return value;
		}
	}

	class UpdateRow
	{
		Map _auditMap;
		Map _userMap;

		public UpdateRow()
		{
		}

		public UpdateRow(Map auditMap, Map userMap)
		{
			this._auditMap = auditMap;
			this._userMap = userMap;
		}
		public Map getAuditMap() {
			return this._auditMap; } 
		public Map getUserMap() { return this._userMap; } 
		public void setAuditMap(Map auditMap) { this._auditMap = auditMap; } 
		public void setUserMap(Map userMap) { this._userMap = userMap;
		}
	}

	class UpdateRows
	{
		List _updateRows;

		public UpdateRows(List updateRows, InformixDBResourceAdapter.UpdateRow lastOne)
		{
			this._updateRows = updateRows;
		}
		public List getUpdateRows() {
			return this._updateRows; } 
		public void setUpdateRows(List updateRows) { this._updateRows = updateRows;
		}
	}

	public static class VariableChecker
	implements VariableResolver
	{
		private Map _schemaMap;

		public VariableChecker(Map schemaMap)
		{
			this._schemaMap = schemaMap;
		}

		public Object resolveVariable(String variable)
		throws WavesetException
		{
			if (!this._schemaMap.containsValue(variable)) {
				ErrorMessage msg = new ErrorMessage(Severity.ERROR, "com.waveset.adapter.RAMessages:DBTABLE_SYNC_UNKNOWN_VARIABLE", variable);
				throw new WavesetException(msg);
			}

			return "";
		}
	}








	private static class DatabaseTableAccountIterator
	implements AccountIterator
	{
		private static final String CLASS = "com.waveset.adapter.InformixDBTableResourceAdapter$DatabaseTableAccountIterator";
		private static final Trace TRACE = TraceManager.getTrace("com.waveset.adapter.InformixDBTableResourceAdapter$DatabaseTableAccountIterator");
		private InformixDBResourceAdapter _adapter;
		private Connection _con;
		private PreparedStatement _st;
		private ResultSet _res;
		private boolean _eof;

		public DatabaseTableAccountIterator(Connection con, InformixDBResourceAdapter adapter, Map searchParams)
		throws WavesetException
		{
			String METHOD = "DatabaseTableAccountIterator";
			TRACE.entry1("DatabaseTableAccountIterator");
			if (TRACE.level1("DatabaseTableAccountIterator")) {
				StringBuffer sb = new StringBuffer(64);
				sb.append("connection=");
				sb.append(con);
				sb.append("adapter=");
				sb.append(adapter);
				sb.append("searchParams=");
				if (searchParams != null)
					sb.append(searchParams.toString());
				else {
					sb.append("null");
				}
				TRACE.info1("DatabaseTableAccountIterator", sb.toString());
				System.out.println("get account acclerator :"+sb.toString());
			}

			boolean success = false;
			try
			{
				String keyColumn = (String)adapter.getRequiredResAttrVal("Key Column");
				StringBuffer selectList = new StringBuffer();
				adapter.addQuotedName(selectList, keyColumn);
				Resource resource = adapter.getResource();
				AccountAttributeType[] attrs = resource.getAccountAttributeTypes();
				for (int i = 0; i < attrs.length; i++) {
					String columnName = attrs[i].getMapName();
					if (Util.length(columnName) <= 0)
					{
						continue;
					}
					if (!Util.equalStrings(columnName, keyColumn)) {
						selectList.append(", ");
						adapter.addQuotedName(selectList, columnName);
					}

				}

				String whereClause = "";
				if (searchParams != null) {
					String whereClauseObj = (String)searchParams.get("searchFilter");
					if (Util.length(whereClauseObj) > 0) {
						whereClause = " where " + whereClauseObj;
					}

				}

				String orderByClause = "";
				if (searchParams != null) {
					String orderByClauseObj = (String)searchParams.get("orderBy");
					if (Util.length(orderByClauseObj) > 0) {
						orderByClause = " ORDER BY " + orderByClauseObj;
					}
				}

				selectList.insert(0, "select ");
				selectList.append(" from ");
				selectList.append(adapter.getRequiredResAttrVal("Table"));
				selectList.append(whereClause);
				selectList.append(orderByClause);
				String q = selectList.toString();

				if (TRACE.level3("DatabaseTableAccountIterator")) {
					StringBuffer msg = new StringBuffer("Executing query: ");
					msg.append(q);
					TRACE.info(0L, "DatabaseTableAccountIterator", msg.toString());
				}

				System.out.println("Get accout iterator query :"+q.toString());
				this._adapter = adapter;
				this._con = con;
				this._st = this._con.prepareStatement(q);
				this._res = this._st.executeQuery();

				if ((this._res == null) || (!this._res.next())) {
					this._eof = true;
				}
				else
				{
					success = true;
				}
			}
			catch (Exception e) {
				TRACE.throwing1("DatabaseTableAccountIterator", e);
				throw new InternalError("DatabaseTableAccountIterator", e);
			}
			finally {
				if (!success)
					close();
			}
			TRACE.exit1("DatabaseTableAccountIterator");
		}

		public void close()
		{
			try
			{
				if (this._res != null)
					this._adapter.closeResult(this._res);
			} catch (Throwable t) {
			}
			finally {
				this._res = null;
			}
			try
			{
				if (this._st != null)
					this._adapter.closeStatement(this._st);
			} catch (Throwable t) {
			}
			finally {
				this._st = null;
			}
			try
			{
				if (this._con != null)
					this._adapter.closeConnection(this._con);
			} catch (Throwable t) {
			}
			finally {
				this._con = null;
			}

			this._eof = true;
		}

		public boolean hasNext()
		throws WavesetException
		{
			return !this._eof;
		}

		public WSUser next()
		throws NoSuchElementException
		{
			String METHOD = "next";
			TRACE.entry1("next");
			if (this._eof) {
				NoSuchElementException nsee = new NoSuchElementException();
				TRACE.throwing1("next", nsee);
				throw nsee;
			}

			WSUser user = null;
			try {
				String id = this._res.getString(1);
				if (id != null) {
					id = id.trim();
				}
				user = new WSUser();
				user.setName(id);

				Resource resource = this._adapter.getResource();
				ResourceInfo info = new ResourceInfo();
				info.setResource(resource);
				info.setAccountID(id);
				user.addResourceInfo(info);

				AccountAttributeType[] attrs = resource.getAccountAttributeTypes();
				for (int i = 0; i < attrs.length; i++) {
					String attrMapName = attrs[i].getMapName();
					String val = this._res.getString(attrMapName);
					if (this._adapter.checkNativeTimestamps(resource, this._res))
					{
						String mapVal = (String)this._adapter.getNativeTimestampsMap().get(attrMapName);
						if ((mapVal != null) && (mapVal.equals("TIMESTAMP")))
						{
							Object ts = this._res.getTimestamp(attrMapName);
							val = ts != null ? ts.toString() : null;
						}
					}

					if (val != null) {
						user.setAttribute(attrs[i].getName(), val);
					}

				}

				if (!this._res.next()) {
					this._eof = true;
					close();
				}
			}
			catch (SQLException e) {
				TRACE.throwing1("next", e);

				this._eof = true;
				close();
				throw new NoSuchElementException();
			}

			TRACE.exit(0L, "next", user);
			return user;
		}
	}

	public static class Param
	{
		public Syntax syntax;
		public Object value;
		public String colName;

		public Param(String colName, Syntax syntax, Object value)
		{
			this.colName = colName;
			this.syntax = syntax;
			this.value = value;
		}
	}
}